hanbt / learn_dl

Deep learning algorithms source code for beginners
Apache License 2.0
1.2k stars 988 forks source link

TypeError: <lambda>() missing 1 required positional argument: 'w' #5

Open whitepaper2 opened 7 years ago

whitepaper2 commented 7 years ago

Hi,I'm run the perceptron.py code,but report error. environment:python3.6 return self.activator( reduce(lambda a, b: a + b, map(lambda xw: xw[0] * xw[1], zip(input_vec, self.weights)) , 0.0) + self.bias)

JeffChau0503 commented 6 years ago

return self.activator( reduce(lambda a, b: a+b, [x_w[0] * x_w[1] for x_w in zip(input_vec, self.weights)], 0.0) + self.bias)

FlyingCat-fa commented 6 years ago

def predict(self, input_vecs): ''' 输入向量,输出感知器的计算结果 ''' output = np.dot(input_vecs, self.weights) + self.bias return element_wise_op(output, self.activator)

def element_wise_op(array, op): ''' 对数组进行element wise操作 '''

只有一个样本array是数而不是数组

if not(array.shape):
    return op(array)
else:
    return [op(array[i]) for i in range(array.shape[0])]