Learn-Python-Programming-Th.../ch04/matrix.multiplication.func.py
2021-10-28 17:37:54 +05:30

13 lines
273 B
Python

# matrix.multiplication.func.py
# this function could also be defined in another module
def matrix_mul(a, b):
return [[sum(i * j for i, j in zip(r, c)) for c in zip(*b)]
for r in a]
a = [[1, 2], [3, 4]]
b = [[5, 1], [2, 1]]
c = matrix_mul(a, b)
print(c)