Open whitepaper2 opened 7 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)
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操作 '''
if not(array.shape):
return op(array)
else:
return [op(array[i]) for i in range(array.shape[0])]
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)