Cleanest way to combine reduce and map in Python
问题 I'm doing a little deep learning, and I want to grab the values of all hidden layers. So I end up writing functions like this: def forward_pass(x, ws, bs): activations = [] u = x for w, b in zip(ws, bs): u = np.maximum(0, u.dot(w)+b) activations.append(u) return activations If I didn't have to get the intermediate values, I'd use the much less verbose form: out = reduce(lambda u, (w, b): np.maximum(0, u.dot(w)+b), zip(ws, bs), x) Bam. All one line, nice and compact. But I can't keep any of