使用数组的先前结果将许多二维数组乘以向量
a = np.array([0, 0, 1000])
b = np.array([[0.1,0.5,0.4],[0.2,0,0.8],[0.1, 0.2,0.7]])
c= np.array([[0,0.5,0.5],[0.3,0,0.7],[0.1,0.4,0.5]])
d= np.array([[0.3,0.5,0.2] ],[0.4,0.3,0.3],[0.1,0.3,0.6]])
我需要乘以这个向量 (a)许多二维数组(b,c,d)。我怎样才能编写一个循环,它接受a并乘以b,然后使用结果乘以c,然后使用该结果乘以d。
我目前正在做这个
result=np.dot(a,b)
result2=np.dot(result,c)
result3=np.dot(result2, d)
但我需要能够循环遍历所有内容,因为我有很多向量和矩阵。
**编辑 np.linalg.multi_dot 适用于这种情况,但我需要像这样获取每个数组的输出
array([130., 330., 540.])
array([225., 326., 449.])```
a = np.array([0, 0, 1000])
b = np.array([[0.1,0.5,0.4],[0.2,0,0.8],[0.1,0.2,0.7]])
c= np.array([[0,0.5,0.5],[0.3,0,0.7],[0.1,0.4,0.5]])
d= np.array([[0.3,0.5,0.2],[0.4,0.3,0.3],[0.1,0.3,0.6]])
I have this vector (a) that I need to multiply by many 2d arrays(b,c,d). How can I write a loop that takes a and multiplies by b and then uses the result, to multiply by c ,and then uses that result to multiply by d.
I am currently doing this
result=np.dot(a,b)
result2=np.dot(result,c)
result3=np.dot(result2,d)
But i need to be able to loop through all as I have many vectors and matrices.
**edit np.linalg.multi_dot works for this case, but I need to get the output of each array like this
array([130., 330., 540.])
array([225., 326., 449.])```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
multi_dot
功能:You can use the
multi_dot
function: