numarray.array can be VERY slow

Robert Kern rkern at ucsd.edu
Sun Apr 10 16:34:07 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?

Because lists of lists of arrays are difficult to work with.

Lists of arrays are relatively easy to work with: numarray checks to see 
if all the items are compatible arrays. If they are, then the arrays are 
all concatenated and you have your final array fairly quickly.

List of lists of arrays are more problematic. Currently, the code 
doesn't check that that the objects it sees are arrays, so it interprets 
the arrays as sequences of sequences, and uses the PySequence_* 
protocol. So you might as well have used list of lists of lists of lists.

See the function setArrayFromSequence in libnumarraymodule.c . If you 
wish to fix this behavior, I'm sure that a patch would be welcomed. 
Further questions should probably go to the numarray mailing list.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the Python-list mailing list