MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / matrix_multiply

Function matrix_multiply

matrix/matrix_multiplication_recursion.py:71–79  ·  view source on GitHub ↗

>>> matrix_multiply(matrix_1_to_4, matrix_5_to_8) [[19, 22], [43, 50]]

(matrix_a: Matrix, matrix_b: Matrix)

Source from the content-addressed store, hash-verified

69
70
71def matrix_multiply(matrix_a: Matrix, matrix_b: Matrix) -> Matrix:
72 """
73 >>> matrix_multiply(matrix_1_to_4, matrix_5_to_8)
74 [[19, 22], [43, 50]]
75 """
76 return [
77 [sum(a * b for a, b in zip(row, col)) for col in zip(*matrix_b)]
78 for row in matrix_a
79 ]
80
81
82def matrix_multiply_recursive(matrix_a: Matrix, matrix_b: Matrix) -> Matrix:

Calls

no outgoing calls

Tested by

no test coverage detected