Write Python program to perform matrix multiplication. Discuss the complexity of algorithm used.

Code:

print ("\n matrix A:")

A= [[1,7,3] , [4,5,6],[7,8,9]]

for i in range(len(A)):

    print(A[i])

print("\n matrix B:")

B=[[5,8,1,2],[6,7,3,0],[4,5,9,1]]

for j in range(len(B)):

    print(B[j])

result=[[0,0,0,0],[0,0,0,0],[0,0,0,0]]

for i in range(len(A)):

    for j in range(len(B[0])):

        for k in range(len(B)):

            result[i][j]+=A[i][k]*B[k][j]

print("\n result matrix A*B=C")

for r in result:

    print(r)

O/P:

Write Python program to perform matrix multiplication. Discuss the complexity of algorithm used.

Fundamental of algorithm

Post a Comment

0 Comments