[SciPy-user] Very slow comparison of arrays of integers

Brian Granger bgranger at scu.edu
Mon Jul 18 00:10:52 CDT 2005


Hello all,

I have some code that is using scipy/numeric and one bottleneck in  
the code consists of comparing arrays or lists of integers.  To my  
dismay, I am finding that using Python lists is 15-20 times _faster_  
than using numeric array's for this.  The problem is that it seems  
that there is no efficient way to compare arrays of integers.

Here is code that clearly demonstrates this problem:

from scipy import *

def test_list(n):
     a = range(100)
     for i in range(n):
         r = (a == a)

def test_array(n):
     a = array(range(100),Int)
     for i in range(n):
         r = allclose(a,a)

The test_list code runs about 20 times as fast as the test_array code  
that uses allclose().

Is there any way of comparing to arrays of integers that would be as  
fast or faster than using lists?  Any hints would be greatly  
appreciated.

Thanks

Brian



More information about the SciPy-user mailing list