【发布时间】:2021-08-06 12:50:02
【问题描述】:
我在 python 中有两个数组。
对于一个,它看起来像
array([[0. , 0.08],
[0.12, 0. ],
[0.12, 0.08]])
对于 b,它看起来像
array([[0.88, 0. ],
[0. , 0.92],
[0. , 0. ]])
我想对这两个数组进行乘法运算,如下所示:
array([[0.08*0.88], ### 1st row of a multiplies 1st row of b without zeros
[0.12*0.92], ### 2nd row of a multiplies 2nd row of b without zeros
[0.12*0.08]]) ### multiplies o.12 and 0.08 together in 3rd row of a without zeros in 3rd row of b
而最终想要的结果是:
array([[0.0704],
[0.1104],
[0.0096]])
我怎样才能做到这一点?我真的可以使用你的帮助。
【问题讨论】:
-
你需要添加更多细节,你没有给出任何你遵循的“规则”来达到你的预期操作;例如你如何确定第三个数组中的最后一个元素是
0.12*0.08? -
哦,是的。实际上我想忽略数组内的零,并对两个数组进行逐行乘法。谢谢你的建议!
标签: python arrays list numpy multiplication