Write a function called Matrix_ mul that takes two 2D list( matrix es) of 3x3named A & B as a parameter and multiplication result of these two matrix
def matrix_mul(A, B):
C = [[0 for _ in range(3)] for _ in range(3)]
for row in range(3):
for col in range(3):
for k in range(3):
C[row][col] += A[row][k] * B[k][col]
return C
def main():
A = [[1, 2, 3], [1, 1, 1], [3, 2, 1]]
B = [[1, -1, 1], [3, 2, 1], [-1, 1, -1]]
C = matrix_mul(A, B)
for row in range(3):
print(C[row])
main()
Comments
Leave a comment