[Numpy-discussion] when and where to use numpy arrays vs nested lists

Charles R Harris charlesr.harris@gmail....
Thu Mar 1 20:40:06 CST 2007


On 3/1/07, Mark P. Miller <mpmusu@cc.usu.edu> wrote:
>
> OK...here goes.  This code is going to look goofy, so please bear in
> mind that it is only an abstraction of what my real code does (which
> happens to provide interesting and meaning insights!).
>
> I've attached saved versions of my interactive python sessions that
> document the phenomenon.  Again, this code mainly serves to illustrate
> what I previously saw.  Please note that I DO NOT a) redefine arrays, or
> b) re-import functions in my real code.
>
> 1)  Fresh install of Enthought python edition and reboot.
>
> Python 2.4.3 - Enthought Edition 1.0.0 (#69, Aug  2 2006, 12:09:59) [MSC
> v.1310 32 bit (Intel)] on win32
> Type "copyright", "credits" or "license()" for more information.
>
>      ****************************************************************
>      Personal firewall software may warn about the connection IDLE
>      makes to its subprocess using this computer's internal loopback
>      interface.  This connection is not visible on any external
>      interface and no data is sent to or received from the Internet.
>      ****************************************************************


In [46]: def test1() :
   ....:     x = normal(0,1,1000)
   ....:

In [47]: def test2() :
   ....:     for i in range(1000) :
   ....:         x = normal(0,1)

 In [50]: t = timeit.Timer('test1()', "from __main__ import test1, normal")

In [51]: t.timeit(100)
Out[51]: 0.022681951522827148

In [52]: t = timeit.Timer('test2()', "from __main__ import test2, normal")

In [53]: t.timeit(100)
Out[53]: 4.3481810092926025

Looks like function call overhead has gone way up or the cost of returning a
float vs an array has gone way up. The loop overhead is about .01 and not
significant. So something is definitely wrong here. Time to go look in trac
;)

I won't comment on the code itself. Tell us what you want to do and I bet we
can speed it up.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070301/6d1c9370/attachment-0001.html 


More information about the Numpy-discussion mailing list