AttributeError:list没有属性点

时间:2017-04-06 03:32:13

标签: python list numpy

我正在尝试测试神经网络。我创造了一个砝码'列表并尝试使用输入数组点击产品。但是dot产品似乎存在问题。代码的粗体部分显示错误。

类BPNetwork:

layerCount = 0
shape = None
weights = [[[ 0.03049199, -0.04634491,  0.0405433 , -0.03799513,  0.04094929,
    -0.09666186,  0.07161143,  0.11686911, -0.1212281 ],
   [ 0.00747107, -0.02739591,  0.16988383,  0.04748638, -0.02052043,
    -0.09041263,  0.01091398, -0.10341986,  0.10367971],
   [-0.00769936,  0.00212671, -0.05626757, -0.06102786,  0.05239374,
     0.17320473,  0.14166611,  0.12951726, -0.04147583],
   [ 0.17410716,  0.14625286, -0.08257581,  0.09635945, -0.04103847,
    -0.05811309, -0.01397631, -0.07126624, -0.03091246],
   [-0.08190238, -0.03037191, -0.0212364 ,  0.17238552,  0.1533649 ,
    -0.01982297, -0.00579448,  0.00125691,  0.01950781]],
  [[ 0.03982875,  0.09886628, -0.10354473, -0.01145922, -0.34038487, -0.0297971 ]]]


def __init__(self, layerSize):

    self.layerCount = len(layerSize) - 1
    self.shape = layerSize

    self._layerInput = []
    self._layerOutput = []

def Run(self, input):

    lnCases = input.shape[0]

    self._layerInput = []
    self._layerOutput = []

    for index in range(self.layerCount):

        #determine layer input

        **if index == 0:
            layerInput = self.weights[0].dot(np.vstack([input.T, np.ones([1, lnCases])]))
        else:
            layerInput = self.weights[index].dot(np.vstack([self._layerOutput[-1], np.ones([1, lnCases])]))**

        self._layerInput.append(layerInput)
        self._layerOutput.append(self.sgm(layerInput))

    return self._layerOutput [-1].T              

1 个答案:

答案 0 :(得分:0)

正如其他人之前所说,self.weights是一个list,而不是一个numpy数组。

例如,将您的__init__功能代码更改为:

def __init__(self, layerSize):

    self.layerCount = len(layerSize) - 1
    self.shape = layerSize

    self._layerInput = []
    self._layerOutput = []

    # convert weights list to numpy array
    self.weights = np.array(self.weights, dtype=np.float)