Matrix multiplication: Difference between revisions
Content added Content deleted
(→{{header|Python}}: add list comp oneliner) |
|||
Line 2,340: | Line 2,340: | ||
Using list comprehensions, multiplying matrices represented as lists of lists. (Input is not validated): |
Using list comprehensions, multiplying matrices represented as lists of lists. (Input is not validated): |
||
<lang python>def mm(A, B): |
<lang python>def mm(A, B): |
||
return [[sum( |
return [[sum(x * B[i][col] for i,x in enumerate(row)) for col in range(len(B[0]))] for row in A]</lang> |
||
Another one, use numpy the most popular array package for python |
Another one, use numpy the most popular array package for python |