我有一个需要执行np.exp(matrix1 @ matrix2)
的函数,但是我收到了错误消息:loop of ufunc does not support argument 0 of type float which has no callable exp method
matrix1
是float
的210x4矩阵,valuesmatrix2
是float
的4乘1,valuesmatrix1 @ matrix2
是float
的210个,valuestype(matrix1 @ matrix)
reports 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
发布于 2020-06-17 03:41:36
exp
在浮点数数组上工作:
In [186]: arr = np.array([1.,2.,3.])
In [187]: np.exp(arr)
Out[187]: array([ 2.71828183, 7.3890561 , 20.08553692])
但如果数组dtype是object
,则不是。
In [188]: np.exp(arr.astype(object))
---------------------------------------------------------------------------
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-188-b80d2a0372d5> in <module>
----> 1 np.exp(arr.astype(object))
TypeError: loop of ufunc does not support argument 0 of type float which has no callable exp method
您的数组可能有混合对象--浮点数、ints、列表,谁知道呢?
===
为什么matrix1 @ matrix2
object
是dtype?matrix1
和matrix2
是什么?@
通常是一个数值操作,尽管它最近被扩展到使用对象dtype。但这是一个较慢的计算。
https://stackoverflow.com/questions/62420661
复制相似问题