【发布时间】:2019-10-20 19:03:53
【问题描述】:
我是这个网站的新手,如果我做的不对,但我遇到了问题,我很抱歉。我应该怎么做才能解决这个问题?
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: 'tuple' 对象没有属性 'T'
【问题讨论】:
-
大概
self.w2没有属性T -
函数
def back(self, x, h, output):需要x、h、输出。你给了我们 x 和 y。哪个输入是 x 和 y。你为“输出”输入了什么? -
idownvotedbecau.se/nomcve - 看起来
self.w2是一个元组,您正在尝试转置它? (假设它是一个 numpy 数组)。问题是没有 MCVE,如果不做假设就很难提供帮助...... -
@NickMartin 什么是 MCVE?
-
@hacquerqop 请添加更完整的代码,包括输入,以便我们重新创建您的错误。