<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Jun 1, 2018 at 9:46 AM, Chris Barker <span dir="ltr"><<a href="mailto:chris.barker@noaa.gov" target="_blank">chris.barker@noaa.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>numpy is also quite a bit slower than raw python for math with (very) small arrays:</div></div></div></div></blockquote><div><br></div><div>doing a bit more experimentation, the advantage is with pure python for over 10 elements (I got bored...). but I noticed that the time for numpy computation is pretty much constant for 2 up to around 100 elements. Which implies that the bulk of the issue is with "startup" costs, rather than fancy indexing or anything like that. so maybe a short cut wouldn't be helpful.</div><div><br></div><div>Note if you use a list comp (the pythonic translation of an array operation) thecrossover point is about 15 elements (in my tests, on my machine...)</div><div><br></div><font face="monospace, monospace">In [90]: % timeit t2 = [x * 10 for x in t]<br><br>920 ns ± 4.88 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)<br><br>-CHB</font></div><div class="gmail_quote"><font face="monospace, monospace"><br><br></font><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><font face="monospace, monospace">In [31]: % timeit t2 = (t[0] * 10, t[1] * 10)<br>162 ns ± 0.79 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)<br><br>In [32]: a<br>Out[32]: array([ 3.4,  5.6])<br><br>In [33]: % timeit a2 = a * 10<br>941 ns ± 7.95 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)</font><div><br></div><div><br></div><div>(I often want to so this sort of thing, not for performance, but for ease of computation -- say you have 2 or three coordinates that represent a point -- it's really nice to be able to scale or shift with array operations, rather than all that indexing -- but it is pretty slo with numpy.</div><div><br></div><div>I've wondered if numpy could be optimized for small 1D arrays, and maybe even 2d arrays with a small fixed second dimension (N x 2, N x 3), by special-casing / short-cutting those cases.</div><div><br></div><div>It would require some careful profiling to see if it would help, but it sure seems possible.</div><div><br></div><div>And maybe scalars could be fit into the same system.</div><div><br></div><div>-CHB</div><span class="HOEnZb"><font color="#888888"><div><br></div><div><br></div><div><br></div><div>-- <br></div></font></span></div><span class="HOEnZb"><font color="#888888"><div class="m_-1822869069879850659gmail_signature" data-smartmail="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            (206) 526-6959   voice<br>7600 Sand Point Way NE   (206) 526-6329   fax<br>Seattle, WA  98115       (206) 526-6317   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</font></span></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            (206) 526-6959   voice<br>7600 Sand Point Way NE   (206) 526-6329   fax<br>Seattle, WA  98115       (206) 526-6317   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div></div>