matrix.py 397 B

12345678910111213
  1. def multiply_matrix(m1, m2):
  2. if len(m1[0]) != len(m2):
  3. return "ERROR"
  4. res = []
  5. for i in range(len(m1)):
  6. res.append([])
  7. for j in range(len(m2[0])):
  8. m2_col = [m2[x][j] for x in range(len(m2))]
  9. res[i].append(sum([x1 * x2 for x1, x2 in zip(m1[i], m2_col)]))
  10. return res
  11. print(multiply_matrix([[1, 2, 3]], [[1], [2], [3]]))