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