'numpy.int64'对象没有属性'dot'

时间:2019-03-12 18:20:04

标签: neural-network gradient-descent numpy-broadcasting

我之前的错误是 'numpy.float64' object has no attribute 'dot'

所以我将代码修改如下

def nonlin(X,deriv=False):
if(deriv==True):
 return x*(1-x)
return 1/(1+np.exp(-x))
np.random.seed(1)
X = np.array([[0,0,1],
[0,1,1],
[1,0,1],
[1,1,1]])

y = np.array([[0],
          [1],
          [1],
          [0]])
syn0=2*np.random.random((3,5))-1
syn1=2*np.random.random((4,5))-1
syn2=2*np.random.random((5,1))-1
for x in range(10000):
l0=X
l1=nonlin(np.dot(l0,syn0))
l2=nonlin(np.dot(l1,syn1))
l3=nonlin(np.dot(l2,syn2))
l3_error=y-l3 
if (x%1000)==0:
 print("Error    is"+str(np.mean(np.abs(l3_error))))
l3_delta=l3_error*nonlin(l3,deriv=True)
l2_error=l3_delta.dot(syn2.T)
l2_delta=l2_error*nonlin(l2,deriv=True)
l1_error=l2_delta.dot(syn1.T)
l1_delta=l1_error*nonlin(l1,deriv=True)
print(l2.dtype)
print(l3_delta.dtype)
l1=l1.astype(np.int64)
l2=l2.astype(np.int64) 
l3=l3.astype(np.int64)
l3_delta=l3_delta.astype(np.int64)
print(l2.dtype)
print(l1.dtype)
l2=l2.astype(np.int64)
syn2 += l2.T.dot(l3_delta)
syn1 += l1.T.dot(l2_delta)
syn0 += l0.T.dot(l1_delta)

更改所有变量的dtype,但仍然以某种方式导致类似的问题。

0 个答案:

没有答案