矩阵乘法
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]]))

作者:九命猫幺
博客出处:http://www.cnblogs.com/yongestcat/
欢迎转载,转载请标明出处。
如果你觉得本文还不错,对你的学习带来了些许帮助,请帮忙点击右下角的推荐
博客出处:http://www.cnblogs.com/yongestcat/
欢迎转载,转载请标明出处。
如果你觉得本文还不错,对你的学习带来了些许帮助,请帮忙点击右下角的推荐

浙公网安备 33010602011771号