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

Why can't I use numpy.logaddexp.reduce?

为什么我不能使用 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

看起来 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