[Chicago] ReLU's pythonic?

Anish Krishnan anish.krishnan.1216 at gmail.com
Fri Feb 17 17:37:12 EST 2017


If you know you're only going to be working with two elements, you could
write your own function that contains the second line of code. In that case
it's readable as well as fast. But it might be overkill, depending on how
often you call out.

On Feb 17, 2017 1:19 PM, "Michael Tamillow" <mikaeltamillow96 at gmail.com>
wrote:

> 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?
>
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> https://mail.python.org/mailman/listinfo/chicago
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20170217/aaddf6c9/attachment.html>


More information about the Chicago mailing list