gpt4 book ai didi

python - 乘法 numpy 的新数组

转载 作者:行者123 更新时间:2023-11-30 22:57:45 24 4
gpt4 key购买 nike

我有一个像这样的数组:

data=np.array(([2,4,8], [10, 20, 30], ...)) # TypeError fixed

我想将结果作为每个数组的每个索引相乘的新数组:

np.array([[64], [6000], ...])

如何使用 numpy 来完成此操作?

最佳答案

嗯,这个结果似乎不是“每个索引的乘法”,但这似乎是您想要的:

result = data.prod(axis=1)

示例:

In [2]: data = numpy.array([[2, 4, 8], [10, 20, 30]])

In [3]: data.prod(axis=1)
Out[3]: array([ 64, 6000])

请参阅docs for numpy.prod了解更多信息。

关于python - 乘法 numpy 的新数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36481354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com