AttributeError: ‘float‘ object has no attribute ‘exp‘
生活随笔
收集整理的這篇文章主要介紹了
AttributeError: ‘float‘ object has no attribute ‘exp‘
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
問題描述:
在sigmod函數的計算過程中出現報錯。
def sigmoid(self, x): # sigmoid激活函數
‘’’
x為1*n向量
‘’’
return 1.0 / (1.0 + np.exp(-x))
從報錯內容中可以知道錯誤原因是float對象沒有exp屬性。
解決方法:
檢查x的屬性
type(x): <class ‘numpy.ndarray’>
檢查x中的數據的屬性如下
type(x[0][2]): <class ‘numpy.float’>
通過以下語句調整x中數據的屬性為float64
x=np.array(x,dtype=np.float64)
問題解決
如果方法有用,請點個贊,方便后面遇到這個錯誤的人識別好的解決方法
總結
以上是生活随笔為你收集整理的AttributeError: ‘float‘ object has no attribute ‘exp‘的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NAVICAT连接oracle数据库的时
- 下一篇: 美发新造型 名家创意示范集锦(图)