Write a Python function "matmult(m1,m2)" that takes as input two matrices using this row-wise representation and returns the matrix product m1*m2 using the same representation.
You may assume that the input matrices are well-formed and have compatible dimensions.
def matmult(m1,m2):
C = [[0 for row in range(len(m1))] for col in range(len(m2[0]))]
for i in range(len(m1)):
for j in range(len(m2[0])):
for k in range(len(m2)):
C[i][j] += m1[i][k]*m2[k][j]
return C
You may assume that the input matrices are well-formed and have compatible dimensions.
def matmult(m1,m2):
C = [[0 for row in range(len(m1))] for col in range(len(m2[0]))]
for i in range(len(m1)):
for j in range(len(m2[0])):
for k in range(len(m2)):
C[i][j] += m1[i][k]*m2[k][j]
return C
This comment has been removed by the author.
ReplyDeleteThis program gives rum time error ....
ReplyDeletematmult([[1,1]],[[3,4],[5,6]])
This comment has been removed by the author.
ReplyDelete