Wahrscheinlich ist es etwas falsch mit den Eingabewerten für X und/oder T. Die Funktion von der Frage ok funktioniert:
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)
Ergebnis:
[[15 16]
[ 5 10]]
[0.9933071490757153, 0.9999546021312976, 0.999999694097773, 0.9999998874648379]
[[ 0.99999969 0.99999989]
[ 0.99330715 0.9999546 ]]
Wahrscheinlich ist es die dtype Ihrer Eingabe Arrays. Ändern X:
X = np.array([[1, 2, 3], [5, 0, 0]], dtype=object)
Gibt:
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
Sieht so aus, als hätten Sie 'np' einem Gleitkommawert zugewiesen. –
Wäre 'X' oder' T' zufällig mit einem dtype von 'object' anstelle von' float64' erstellt worden? – user2357112
Nein, neu zugewiesen wurde nicht passieren. type (X) ist numpy ndarray, type (X [0] [0]) ist float –