1

为什么我不能使用 numpy.logaddexp.reduce?

In [46]: a = np.array([1,5, 3, 2])

In [47]: np.logaddexp.reduce(a)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-47-701e5f4017fe> in <module>()
----> 1 np.logaddexp.reduce(a)

TypeError: No loop matching the specified signature was found for ufunc logaddexp
4

1 回答 1

3

看起来该reduce函数不接受整数数组。使用浮点数组:

In [28]: a = np.array([1.0, 5.0, 3.0, 2.0])

In [29]: np.logaddexp.reduce(a)
Out[29]: 5.1851824526038124

或使用dtype参数:

In [34]: a = np.array([1, 5, 3, 2])

In [35]: np.logaddexp.reduce(a, dtype=np.float64)
Out[35]: 5.1851824526038124
于 2015-04-14T11:48:46.420 回答