[Chicago] ReLU's pythonic?

Chris Foresman foresmac at gmail.com
Fri Feb 17 14:31:15 EST 2017


I’d suggest the former is the way to go here, since it more closely aligns with the mathematical model you are using. I mean, it’s sort of a side effect that a ternary statement also implements the max() function when choosing between two values.


Chris Foresman
foresmac at gmail.com




> On Feb 17, 2017, at 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/a377daa1/attachment.html>


More information about the Chicago mailing list