来自乘法 numpy 的新数组
New array from multiplication numpy
我有一个这样的数组:
data=np.array(([2,4,8], [10, 20, 30], ...)) # TypeError fixed
我想将结果作为每个数组的每个索引的乘积的新数组:
np.array([[64], [6000], ...])
如何使用 numpy 完成?
嗯,这个结果似乎不是 "multiplication of each of the indices",但这似乎是您想要的:
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
。
我有一个这样的数组:
data=np.array(([2,4,8], [10, 20, 30], ...)) # TypeError fixed
我想将结果作为每个数组的每个索引的乘积的新数组:
np.array([[64], [6000], ...])
如何使用 numpy 完成?
嗯,这个结果似乎不是 "multiplication of each of the indices",但这似乎是您想要的:
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
。