Matrix multiplication: Difference between revisions

→‎{{header|Python}}: add list comp oneliner
m (explanatory note added)
(→‎{{header|Python}}: add list comp oneliner)
Line 2,338:
m1)</lang>
 
Using list comprehensions, multiplying matrices represented as lists of lists. (Input is not validated):
<lang python>def mm(A, B):
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
Anonymous user