[Chicago] ReLU's pythonic?

Michael Tamillow mikaeltamillow96 at gmail.com
Fri Feb 17 14:19:10 EST 2017


Hey groupies!


I am curious about what people consider more pythonic.

The zen of python says:


"There should be one-- and preferably only one --obvious way to do it."

And so, I've been reading about ReLUs recently in Neural Networks
(Rectified Linear Units), which all give the equation:

f(x) = max(0, x)

But, whenever I see this I think:

f(x) = 0 if x < 0 else x

So I am wondering if there are any thoughts on what is more pythonic.
The second way ran 4x as fast for me in python using the built in max
function over 10,000 iterations. Which makes sense since the max
function must do at least one comparison operation.

Thoughts? Is speed the ultimate measure of what's pythonic? Or something else?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20170217/85a4b7c3/attachment.html>


More information about the Chicago mailing list