pyschools Topic 6: Question 11题目:矩阵乘法
Write a function that does matrix multiplication.
The product of a mxn matrix with a nxp matrix results in a mxp matrix.
A mxn matrix, with m rows and n columns, can be represented using nested lists.
Am,n = [ [x11, x12, ..., x1n], ..., [xm1, ..., xmn] ]
def MatrixProduct(a, b):
D = []
for i in range(len(a)):
C = []
for j in range(len(b[0])):
total = 0
for k in range(len(a[0])):
total += a[i][k] * b[k][j]
C.append(total)
D.append(C)
return D
print(MatrixProduct([[1,0],[0,0]], [[0,1],[1,0]]))
