Python矩阵乘法整数使用用于循环
from numpy import linalg
from numpy import matmul
A = [[1,2],[2,3]]
b = [[5],[2]
Ab = []
nrows = 2
ncols = 2
for i in range(0,nrows):
sum = 0
for j in range(0,ncols):
sum = sum + A[i][j] * b[j][0]
Ab[?] = ?
print(Ab)
exit()
我不确定该提出的问题标记为“ ab [?] =?”。我尝试了“ ab [i] = sum”,但这似乎不起作用。我需要此代码来打印A和b中列出的乘以矩阵的结果。 行是“ sum = sum + a [i] [j] * b [j] [0]“对吗?
from numpy import linalg
from numpy import matmul
A = [[1,2],[2,3]]
b = [[5],[2]
Ab = []
nrows = 2
ncols = 2
for i in range(0,nrows):
sum = 0
for j in range(0,ncols):
sum = sum + A[i][j] * b[j][0]
Ab[?] = ?
print(Ab)
exit()
I am not sure what to put in place of the questions marks " Ab[?] = ?" I tried "Ab[i] = sum" but that does not seem to be working. I need this code to print the results of the multiplied matrices listed in A and b.
Is the line "sum = sum + A[i][j] * b[j][0]" right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论