這裏是我的代碼:NumPy的AttributeError的:「浮動」對象有沒有屬性「EXP」
def sigmoid(X, T): return (1.0/(1.0 + np.exp(-1.0*np.dot(X, T))))
而此行給我的錯誤「AttributeError的:‘浮動’對象有沒有屬性‘EXP’」。 X,T是Numpy ndarray。
這裏是我的代碼:NumPy的AttributeError的:「浮動」對象有沒有屬性「EXP」
def sigmoid(X, T): return (1.0/(1.0 + np.exp(-1.0*np.dot(X, T))))
而此行給我的錯誤「AttributeError的:‘浮動’對象有沒有屬性‘EXP’」。 X,T是Numpy ndarray。
也許有一些錯誤X的輸入值和/或T.從有問題的功能工作正常:
import numpy as np
from math import e
def sigmoid(X, T):
return 1.0/(1.0 + np.exp(-1.0 * np.dot(X, T)))
X = np.array([[1, 2, 3], [5, 0, 0]])
T = np.array([[1, 2], [1, 1], [4, 4]])
print X.dot(T)
print
# Just to see if values are ok
print [1./(1. + e ** el) for el in [-5, -10, -15, -16]]
print
print sigmoid(X, T)
結果:
[[15 16]
[ 5 10]]
[0.9933071490757153, 0.9999546021312976, 0.999999694097773, 0.9999998874648379]
[[ 0.99999969 0.99999989]
[ 0.99330715 0.9999546 ]]
也許它是你輸入的D型陣列。更改X到:
X = np.array([[1, 2, 3], [5, 0, 0]], dtype=object)
給出:
Traceback (most recent call last):
File "/[...]/stackoverflow_sigmoid.py", line 24, in <module>
print sigmoid(X, T)
File "/[...]/stackoverflow_sigmoid.py", line 14, in sigmoid
return 1.0/(1.0 + np.exp(-1.0 * np.dot(X, T)))
AttributeError: exp
您轉換類型np.dot(X, T)
到FLOAT32這樣的:
z=np.array(np.dot(X, T),dtype=np.float32)
def sigmoid(X, T):
return (1.0/(1.0 + np.exp(-z)))
希望它最終將工作!
看起來您已將'np'重新賦值爲float值。 –
'X'或'T'偶然會被'object'的dtype而不是'float64'創建? – user2357112
不,重新分配沒有發生。類型(X)是numpy ndarray,類型(X [0] [0])是float –