首页 > 其他 > 详细

矩阵乘法

时间:2020-08-05 09:16:43      阅读:76      评论:0      收藏:0      [点我收藏+]

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]]))

技术分享图片

矩阵乘法

原文:https://www.cnblogs.com/yongestcat/p/13437646.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!