我是这个网站的新手,如果不能正确执行此操作但遇到问题,抱歉。我该怎么办才能解决此问题?
import numpy as np
X = (([0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0]))
h = (([0, 0], [0, 1], [1, 0], [1, 1]))
class NeuralNetworks(object):
def __init__(self):
self.InputSize = 4
self.OutputSize = 2
self.HiddenSize = 3
self.w1 = np.random.randn(self.InputSize, self.HiddenSize)
self.w2 = np.random.randn(self.HiddenSize, self.OutputSize)
def forward(self, x):
self.z = np.dot(x, self.w1)
self.z2 = self.sigmoid(self.z)
self.z3 = np.dot(self.z2, self.w2)
output = self.sigmoid(self.z3)
return output
def sigmoid(self, k ):
return 1/(1 + np.exp(-k))
def delta (self,k):
return k*(1-k)
def back(self, x, h, output):
self.error = h-output
self.outputdelta = self.error *self.delta(output)
self.z2error=self.outputdelta.dot(self.w2.T)
self.z2delta = self.z2error * self.delta(self.z2)
self.w1 += x.T.dot(self.z2delta)
self.w2 += self.z2.T.dot(self.outputdelta)
AttributeError:“元组”对象没有属性“ T”
答案 0 :(得分:1)
我假设您的输入应为NumPy数组。您正在传递元组(用括号()
表示)。这样做就足够了:
import numpy as np
X = np.array(([0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 0]))
y = np.array(([0, 0], [0, 1], [1, 0], [1, 1]))