Python矩阵乘法整数使用用于循环

发布于 2025-01-18 08:35:57 字数 406 浏览 0 评论 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()

我不确定该提出的问题标记为“ 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文