Isn't the max function used for iterables so a list of two elements even though it works is sort of overkill ?<br><div class="gmail_quote"><div dir="ltr">On Fri, Feb 17, 2017 at 1:37 PM John Cronan <<a href="mailto:kyle@pbx.org">kyle@pbx.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">On the performance aspect: you have discovered function call overhead.<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I don't think speed is the ultimate measure of "pythonic." I think readability is a better candidate. But, certainly constructs that performs worse than alternatives by more than just a constant factor are unlikely to be adopted as ideal pythonic forms.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">-JK</div></div><div class="gmail_extra gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg">On Fri, Feb 17, 2017 at 1:19 PM, Michael Tamillow <span dir="ltr" class="gmail_msg"><<a href="mailto:mikaeltamillow96@gmail.com" class="gmail_msg" target="_blank">mikaeltamillow96@gmail.com</a>></span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">Hey groupies!<div class="gmail_msg"><br class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I am curious about what people consider more pythonic.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The zen of python says:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><pre class="m_8706931391034305751m_7002145582339150270gmail-literal-block gmail_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_8706931391034305751m_7002145582339150270gmail-literal-block gmail_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="gmail_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="gmail_msg"><br class="gmail_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="gmail_msg"><br class="gmail_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="gmail_msg"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;white-space:normal" class="gmail_msg">But, whenever I see this I think:</span><br class="gmail_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="gmail_msg"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;white-space:normal" class="gmail_msg"><br class="gmail_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="gmail_msg"><br class="gmail_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="gmail_msg"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;white-space:normal" class="gmail_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="gmail_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="gmail_msg"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;white-space:normal" class="gmail_msg"><br class="gmail_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="gmail_msg"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;white-space:normal" class="gmail_msg">Thoughts? Is speed the ultimate measure of what's pythonic? Or something else?</span></div></pre></div></div></div>
<br class="gmail_msg">_______________________________________________<br class="gmail_msg">
Chicago mailing list<br class="gmail_msg">
<a href="mailto:Chicago@python.org" class="gmail_msg" target="_blank">Chicago@python.org</a><br class="gmail_msg">
<a href="https://mail.python.org/mailman/listinfo/chicago" rel="noreferrer" class="gmail_msg" target="_blank">https://mail.python.org/mailman/listinfo/chicago</a><br class="gmail_msg">
<br class="gmail_msg"></blockquote></div><br class="gmail_msg"></div>
_______________________________________________<br class="gmail_msg">
Chicago mailing list<br class="gmail_msg">
<a href="mailto:Chicago@python.org" class="gmail_msg" target="_blank">Chicago@python.org</a><br class="gmail_msg">
<a href="https://mail.python.org/mailman/listinfo/chicago" rel="noreferrer" class="gmail_msg" target="_blank">https://mail.python.org/mailman/listinfo/chicago</a><br class="gmail_msg">
</blockquote></div>