The first one you mention is the answer I received on StackOverflow when I asked that very question.
The second one doesn't do matrix multiplication though, since the result should be a matrix itself. That's why they end up with the nested list comprehension (I haven't checked it though). I think it's easier to just use numpy.
3
u/TheBlackCat13 Sep 22 '15
I think the itertools grouper recipe is easier:
I think the itertools
dotproductrecipe is much easier: