In the course of trying to speed up matplotlib, I did a little experiment that may indicate a place where numpy can be sped up: the creation of a 2-D array from a list of tuples. Using the attached script, I find that numarray is roughly 5x faster than either numpy or Numeric:

[EMAIL PROTECTED] tests]$ python test_array.py
array size: 10000 2
number of loops: 100
numpy 10.89
numpy2 6.57
numarray 1.77
numarray2 0.76
Numeric 8.2
Numeric2 4.36

[EMAIL PROTECTED] tests]$ python test_array.py
array size: 100 2
number of loops: 100
numpy 0.11
numpy2 0.06
numarray 0.03
numarray2 0.01
Numeric 0.08
Numeric2 0.05

The numarray advantage persists for relatively small arrays (100x2; second example) and larger ones (10000x2; first example). In each case, the second test for a given package (e.g., numpy2) is the result with the type of the array element specified in advance, and the first (e.g., numpy) is without such specification.

The versions I used are:

In [3]:Numeric.__version__
Out[3]:'24.0b2'
In [5]:numarray.__version__
Out[5]:'1.4.1'
In [7]:numpy.__version__
Out[7]:'0.9.9.2584'


Eric
''' Test speed of creation of a 2-D array from a list of tuples.
'''

import numpy, numarray, Numeric
from time import clock
nloops = 100
ntuples = 10000


z = zip(range(ntuples), range(ntuples))
print "array size:", len(z), len(z[0])
print "number of loops:", nloops

t0 = clock()
for i in range(nloops):
    zz = numpy.array(z)
print "numpy", clock()-t0

t0 = clock()
for i in range(nloops):
    zz = numpy.array(z, dtype=numpy.int32)
print "numpy2", clock()-t0


t0 = clock()
for i in range(nloops):
    zz = numarray.array(z)
print "numarray", clock()-t0

t0 = clock()
for i in range(nloops):
    zz = numarray.array(z, typecode=numarray.Int32)
print "numarray2", clock()-t0


t0 = clock()
for i in range(nloops):
    zz = Numeric.array(z)
print "Numeric", clock()-t0

t0 = clock()
for i in range(nloops):
    zz = Numeric.array(z, typecode=Numeric.Int32)
print "Numeric2", clock()-t0

_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion

Reply via email to