【发布时间】:2020-06-17 14:01:23
【问题描述】:
我有一个函数需要执行np.exp(matrix1 @ matrix2),但我收到错误消息:loop of ufunc does not support argument 0 of type float which has no callable exp method
-
matrix1是float值的 210 x 4 矩阵 -
matrix2是float值的 4 x 1 -
matrix1 @ matrix2是float值的 210 乘 1 -
type(matrix1 @ matrix)举报numpy.ndarray
numpy.exp() 需要 array_like 参数,所以我不明白为什么会这样。
错误详情:
newval = np.exp(matrix1 @ matrix2)
AttributeError Traceback (most recent call last)
AttributeError: 'float' object has no attribute 'exp'
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
<ipython-input-563-7924faaa390b> in <module>
----> 1 np.exp(matrix1 @ matrix2)
TypeError: loop of ufunc does not support argument 0 of type float which has no callable exp method
【问题讨论】:
-
似乎您使用了变量
np在程序中的某处存储浮点值,并且将numpy的别名覆盖为np。 -
什么是
(matrix1 @ matrix).dtype? -
可能相关:stackoverflow.com/a/47208873/642070。可能是当 np.exp 遍历该系列时,它假定包含的对象将具有
exp方法。 -
tdelaney,dtype 是“dtype('O')”
-
amzon-ex,我将 numpy 导入为 np。 np 没有被用作变量。