[Numpy-discussion] treating numpy arrays like lists is slow

Sasha ndarray at mac.com
Fri Feb 3 15:11:10 EST 2006


This is so because scalar math is very slow in numpy.  This will
improve with the introduction of the scalarmath module.

> python -m timeit -s "from numpy import float_; x = float_(2)" "2.*x"
100000 loops, best of 3: 15.8 usec per loop
> python -m timeit -s "x = 2." "2.*x"
1000000 loops, best of 3: 0.261 usec per loop



On 2/3/06, Jeff Whitaker <jswhit at fastmail.fm> wrote:
>
> Hi:
>
> I've noticed that code like this is really slow in numpy (0.9.4):
>
> import numpy as NP
> a = NP.ones(10000,'d')
> a = [2.*a1 for a1 in a]
>
>
> the last line takes 0.17 seconds on my G5, while for Numeric and
> numarray it takes only 0.01.  Anyone know the reason for this?
>
> -Jeff
>
> --
> Jeffrey S. Whitaker         Phone  : (303)497-6313
> Meteorologist               FAX    : (303)497-6449
> NOAA/OAR/PSD  R/PSD1        Email  : Jeffrey.S.Whitaker at noaa.gov
> 325 Broadway                Office : Skaggs Research Cntr 1D-124
> Boulder, CO, USA 80303-3328 Web    : http://tinyurl.com/5telg
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>




More information about the NumPy-Discussion mailing list