hanbt / learn_dl

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

perceptron.py 中,让人费解的 0.0的问题,感觉很多余 #21

Closed jiangzhonglian closed 6 years ago

jiangzhonglian commented 6 years ago

没太搞懂 0.0 是啥意思,怎么感觉是多余的?难道是??float类型的转化?

def predict(self, input_vec):
    '''
    输入向量,输出感知器的计算结果
    '''
    # 把input_vec[x1,x2,x3...]和weights[w1,w2,w3,...]打包在一起
    # 变成[(x1,w1),(x2,w2),(x3,w3),...]
    # 然后利用map函数计算[x1*w1, x2*w2, x3*w3]
    # 最后利用reduce求和
    return self.activator(
        reduce(lambda a, b: a + b,
               map(lambda (x, w): x * w, zip(input_vec, self.weights)),
               0.0) + self.bias)
wangchongwu commented 6 years ago

reduce(function, sequence[, initial]) -> value

jiangzhonglian commented 6 years ago

谢谢大佬,懂了!