首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >python3 np.exp(matrix1 * matrix2)中的错误-“ufunc循环不支持没有可调用exp方法的浮点数类型的参数0”

python3 np.exp(matrix1 * matrix2)中的错误-“ufunc循环不支持没有可调用exp方法的浮点数类型的参数0”
EN

Stack Overflow用户
提问于 2020-06-17 02:46:35
回答 1查看 1.6K关注 0票数 1

我有一个需要执行np.exp(matrix1 @ matrix2)的函数,但是我收到了错误消息:loop of ufunc does not support argument 0 of type float which has no callable exp method

  • matrix1float的210x4矩阵,values
  • matrix2float的4乘1,values
  • matrix1 @ matrix2float的210个,values
  • type(matrix1 @ matrix) reports numpy.ndarray

numpy.exp()期望有一个array_like参数,所以我不明白为什么会这样。

错误详细信息:

代码语言:javascript
运行
复制
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
​
EN

回答 1

Stack Overflow用户

发布于 2020-06-17 03:41:36

exp在浮点数数组上工作:

代码语言:javascript
运行
复制
In [186]: arr = np.array([1.,2.,3.])                                                                            
In [187]: np.exp(arr)                                                                                           
Out[187]: array([ 2.71828183,  7.3890561 , 20.08553692])

但如果数组dtype是object,则不是。

代码语言:javascript
运行
复制
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?matrix1matrix2是什么?@通常是一个数值操作,尽管它最近被扩展到使用对象dtype。但这是一个较慢的计算。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62420661

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档