[Numpy-discussion] Numpy array performance issue

Bruno Santos bacmsantos@gmail....
Wed Feb 24 09:55:51 CST 2010

Hello everyone,

I am using numpy arrays whenever I demand performance from my
algorithms. Nevertheless, I am having a performance issue at the moment
mainly because I am iterating several times over numpy arrays. Fot that
reason I decided to use timeit to see the performance of different versions
of the same procedure. What surprised me was that in fact Python lists are
performing almost ten times faster than numpy. Why is this happening.
My test code is this:

list1 = [random.randint(0,20) for i in xrange(100)]
 list2 = numpy.zeros(100,dtype='Int64')
for i in xrange(100):list2[i]=random.randint(0,20)
def test1(listx):

return len([elem for elem in list if elem >=10])

t = timeit.Timer("test1(list1)","from __main__ import *")
>>> t.timeit()
t = timeit.Timer("test1(list2)","from __main__ import *")
>>> t.timeit()

Thanks in advance,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100224/d801be93/attachment.html 

More information about the NumPy-Discussion mailing list