numarray.array can be VERY slow

Jim jbo at cannedham.ee.ed.ac.uk
Wed Apr 13 05:58:23 EDT 2005


Edward C. Jones wrote:
> Steven Bethard wrote:
> 
>  > As mentioned, this has nothing to do with numarray, and everything to
>  > do with your inexplicable use of lists.  Why don't you just write this
>  > as:
>  >
>  > arr = numarray.ones((8, 8, 256, 256), Float64)
> 
> The code I posted was simplified from a larger program which I have now 
> revised. But I still ask: why did it take 4.3 seconds to run?

Is the simple answer not that repeated use of array.append is 
inefficient as python has to repeatedly re-allocate memory for the array?

I had a similar problem as I ran a simulation and appended the results 
to a results set. Now I create a list of objects of the size required 
and the overwrite them. Much faster :)

Jim
Getting in there late cos I've been skiving



More information about the Python-list mailing list