<div dir="ltr">Well, turns out I was wrong, which is surprisingly common. This is more like the case of enjoying doing what's good for you instead of making a decision between what's good and what's enjoyable.<div><br></div><div><a href="https://github.com/MikeTam1021/ReLU/blob/master/ReLU%20performance%20python.ipynb" target="_blank">https://github.com/<wbr>MikeTam1021/ReLU/blob/master/<wbr>ReLU%20performance%20python.<wbr>ipynb</a><br></div><div><br></div><div>after some of the comments I looked into broadcasting with the built in max function which is much faster than any other way to run the ReLU.</div><div><br></div><div>Thanks!</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Feb 18, 2017 at 4:39 AM, Jason Wirth <span dir="ltr"><<a href="mailto:wirth.jason@gmail.com" target="_blank">wirth.jason@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The ternary operator is easier to understand for me in this context. Relu's take values less than zero and set them to zero. That's the important part and the ternary operator captures the less than part, the max is irrelevant. It's not that you care about the maximum value, you just don't want any negative values. Where as when I see max it makes me think of two numbers (often positive)  and you want the larger of the two because you care about magnitude. E.g.<br><br>salary = max(job1, job2)<br><br>Also as a general point, beware the ternary operator. Your case is simple but t can get really long and really messy, becoming an unreadable pile of garbage. <br><br>result = obj.process().result if <a href="http://obj.name" target="_blank">obj.name</a> in found_names and obj.settings or obj.user_settings else obj.process(defaults).get_<wbr>result()<div class="HOEnZb"><div class="h5"><br><br><br><div class="gmail_quote"><div dir="ltr">On Fri, Feb 17, 2017 at 4:37 PM Anish Krishnan <<a href="mailto:anish.krishnan.1216@gmail.com" target="_blank">anish.krishnan.1216@gmail.com</a><wbr>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class="m_-8002228817358243211gmail_msg">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.</div><div class="gmail_extra m_-8002228817358243211gmail_msg"><br class="m_-8002228817358243211gmail_msg"><div class="gmail_quote m_-8002228817358243211gmail_msg">On Feb 17, 2017 1:19 PM, "Michael Tamillow" <<a href="mailto:mikaeltamillow96@gmail.com" class="m_-8002228817358243211gmail_msg" target="_blank">mikaeltamillow96@gmail.com</a>> wrote:<br type="attribution" class="m_-8002228817358243211gmail_msg"><blockquote class="gmail_quote m_-8002228817358243211gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="m_-8002228817358243211gmail_msg">Hey groupies!<div class="m_-8002228817358243211gmail_msg"><br class="m_-8002228817358243211gmail_msg"><div class="m_-8002228817358243211gmail_msg"><br class="m_-8002228817358243211gmail_msg"></div><div class="m_-8002228817358243211gmail_msg">I am curious about what people consider more pythonic.</div><div class="m_-8002228817358243211gmail_msg"><br class="m_-8002228817358243211gmail_msg"></div><div class="m_-8002228817358243211gmail_msg">The zen of python says:</div><div class="m_-8002228817358243211gmail_msg"><br class="m_-8002228817358243211gmail_msg"></div><div class="m_-8002228817358243211gmail_msg"><br class="m_-8002228817358243211gmail_msg"></div><div class="m_-8002228817358243211gmail_msg"><pre class="m_-8002228817358243211m_5162784227927531710m_-6636811725812200041gmail-literal-block m_-8002228817358243211gmail_msg" style="box-sizing:border-box;margin-top:0px;margin-bottom:1.3125em;padding:0.5em;border:0px;font-variant-numeric:inherit;font-stretch:inherit;font-size:15px;line-height:1.875;font-family:consolas,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;vertical-align:baseline;white-space:pre-wrap;word-wrap:break-word;background-image:inherit;background-position:inherit;background-size:inherit;background-repeat:inherit;background-origin:inherit;background-clip:inherit;background-color:rgb(249,249,249);color:rgb(68,68,68)">"There should be one-- and preferably only one --obvious way to do it."</pre><pre class="m_-8002228817358243211m_5162784227927531710m_-6636811725812200041gmail-literal-block m_-8002228817358243211gmail_msg" style="box-sizing:border-box;margin-top:0px;margin-bottom:1.3125em;padding:0.5em;border:0px;font-variant-numeric:inherit;font-stretch:inherit;line-height:1.875;vertical-align:baseline;word-wrap:break-word;background-image:inherit;background-position:inherit;background-size:inherit;background-repeat:inherit;background-origin:inherit;background-clip:inherit"><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;white-space:normal;background-color:rgb(249,249,249)" class="m_-8002228817358243211gmail_msg">And so, I've been reading about ReLUs recently in Neural Networks (Rectified Linear Units), which all give the equation:</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;white-space:normal;background-color:rgb(249,249,249)" class="m_-8002228817358243211gmail_msg"><br class="m_-8002228817358243211gmail_msg"></div>f(x) = max(0, x)<div style="color:rgb(68,68,68);font-family:consolas,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;font-size:15px;white-space:pre-wrap;background-color:rgb(249,249,249)" class="m_-8002228817358243211gmail_msg"><br class="m_-8002228817358243211gmail_msg"></div><div style="color:rgb(68,68,68);font-family:consolas,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;font-size:15px;white-space:pre-wrap;background-color:rgb(249,249,249)" class="m_-8002228817358243211gmail_msg"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;white-space:normal" class="m_-8002228817358243211gmail_msg">But, whenever I see this I think:</span><br class="m_-8002228817358243211gmail_msg"></div><div style="color:rgb(68,68,68);font-family:consolas,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;font-size:15px;white-space:pre-wrap;background-color:rgb(249,249,249)" class="m_-8002228817358243211gmail_msg"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;white-space:normal" class="m_-8002228817358243211gmail_msg"><br class="m_-8002228817358243211gmail_msg"></span></div>f(x) = 0 if x < 0 else x<div style="color:rgb(68,68,68);font-family:consolas,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;font-size:15px;white-space:pre-wrap;background-color:rgb(249,249,249)" class="m_-8002228817358243211gmail_msg"><br class="m_-8002228817358243211gmail_msg"></div><div style="color:rgb(68,68,68);font-family:consolas,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;font-size:15px;white-space:pre-wrap;background-color:rgb(249,249,249)" class="m_-8002228817358243211gmail_msg"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;white-space:normal" class="m_-8002228817358243211gmail_msg">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.</span><br class="m_-8002228817358243211gmail_msg"></div><div style="color:rgb(68,68,68);font-family:consolas,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;font-size:15px;white-space:pre-wrap;background-color:rgb(249,249,249)" class="m_-8002228817358243211gmail_msg"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;white-space:normal" class="m_-8002228817358243211gmail_msg"><br class="m_-8002228817358243211gmail_msg"></span></div><div style="color:rgb(68,68,68);font-family:consolas,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;font-size:15px;white-space:pre-wrap;background-color:rgb(249,249,249)" class="m_-8002228817358243211gmail_msg"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;white-space:normal" class="m_-8002228817358243211gmail_msg">Thoughts? Is speed the ultimate measure of what's pythonic? Or something else?</span></div></pre></div></div></div>
<br class="m_-8002228817358243211gmail_msg">______________________________<wbr>_________________<br class="m_-8002228817358243211gmail_msg">
Chicago mailing list<br class="m_-8002228817358243211gmail_msg">
<a href="mailto:Chicago@python.org" class="m_-8002228817358243211gmail_msg" target="_blank">Chicago@python.org</a><br class="m_-8002228817358243211gmail_msg">
<a href="https://mail.python.org/mailman/listinfo/chicago" rel="noreferrer" class="m_-8002228817358243211gmail_msg" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/chicago</a><br class="m_-8002228817358243211gmail_msg">
<br class="m_-8002228817358243211gmail_msg"></blockquote></div></div>
______________________________<wbr>_________________<br class="m_-8002228817358243211gmail_msg">
Chicago mailing list<br class="m_-8002228817358243211gmail_msg">
<a href="mailto:Chicago@python.org" class="m_-8002228817358243211gmail_msg" target="_blank">Chicago@python.org</a><br class="m_-8002228817358243211gmail_msg">
<a href="https://mail.python.org/mailman/listinfo/chicago" rel="noreferrer" class="m_-8002228817358243211gmail_msg" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/chicago</a><br class="m_-8002228817358243211gmail_msg">
</blockquote></div>
</div></div><br>______________________________<wbr>_________________<br>
Chicago mailing list<br>
<a href="mailto:Chicago@python.org">Chicago@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/chicago" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/chicago</a><br>
<br></blockquote></div><br></div>