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

Mark P. Miller mpmusu at cc.usu.edu
Thu Mar 1 18:16:18 EST 2007


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.
     ****************************************************************

IDLE 1.1.3      ==== No Subprocess ====
 >>> import numpy
 >>> numpy.__version__
'0.9.9.2706'
 >>> def numpytest():
	array1=numpy.zeros((100,100),int)
	from numpy.random import normal
	for aa in xrange(25,50):
		for bb in xrange(25,50):
			x1=int(normal(0,1))
			x2=int(normal(0,1))
			array1[aa,bb]=array1[x1,x2]

			
 >>> import timeit
 >>> t=timeit.Timer("numpytest()", "from __main__ import numpytest")
 >>> t.timeit(100)
1.110151150495426
 >>> t.timeit(100)
1.1139172716085568
 >>> t.timeit(100)
1.1248401682336748
 >>>

2)  Install Numpy 1.0.1 from "numpy-1.0.1.win32-py2.4.exe" (downloaded 
today).  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.
     ****************************************************************

IDLE 1.1.3      ==== No Subprocess ====
 >>> import numpy
 >>> numpy.__version__
'1.0.1'
 >>> def numpytest():
	array1=numpy.zeros((100,100),int)
	from numpy.random import normal
	for aa in xrange(25,50):
		for bb in xrange(25,50):
			x1=int(normal(0,1))
			x2=int(normal(0,1))
			array1[aa,bb]=array1[x1,x2]

 >>> import timeit
 >>> t=timeit.Timer("numpytest()", "from __main__ import numpytest")
 >>> t.timeit(100)
17.143569084897678
 >>> t.timeit(100)
17.183305140737161
 >>> t.timeit(100)
17.283449432818969
 >>>

Hope this helps or is informative somehow.

-Mark


Robert Kern wrote:
> Mark P. Miller wrote:
> 
>> Now however, I'm seeing perhaps a more serious problem:   The test 
>> program that I'm working with went from taking ~80 seconds to run to 
>> taking over 10 minutes to run.  I've rolled back to my old numpy version 
>> and confirmed that the old version was much faster.  I also tried 
>> re-installing 1.0.1, and once again am seeing much slower runtimes.
> 
> Give us a small, self-contained benchmark, and we'll see what we can do.
> 

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: numpy 0.9.9.2706.py
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070301/0bcab617/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: numpy 1.0.1.py
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070301/0bcab617/attachment-0001.ksh>


More information about the NumPy-Discussion mailing list