矩阵乘法

pyschools Topic 6: Question 11题目:矩阵乘法

Write a function that does matrix multiplication.

The product of a mx n matrix with a nx p matrix results in a mx p matrix.

A mxn matrix, with m rows and n columns, can be represented using nested lists.

Am,n = [ [x11, x12, …, x1n], …, [xm1, …, xmn] ]

bash;gutter:true; 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</p> <p>print(MatrixProduct([[1,0],[0,0]], [[0,1],[1,0]]))

矩阵乘法

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

Original: https://www.cnblogs.com/yongestcat/p/13437646.html
Author: 九命猫幺
Title: 矩阵乘法

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/565630/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球