[Numpy-discussion] Avoiding array-scalar arithmetic?

Travis Oliphant oliphant.travis at ieee.org
Wed Sep 13 14:07:03 CDT 2006


Ryan Gutenkunst wrote:
> Hi all,
>
> I'm migrating an application from Numeric to numpy, and I've run into a 
> significant application slowdown related to arithmetic on array-scalars.
>
>   
Yeah,  that is a common thing.   There are two factors:  1) array 
indexing and 2) array scalar math.

I don't think array scalar math has to be slower in principle then 
Python code.   I think it's ability to handle interaction with multiple 
scalars that is operating more slowly right now.  It could be sped up.

The array indexing code is slower (in fact Numeric's indexing code is 
slower then just using lists also). 
> I'm guessing speeding up the scalar-array math would be difficult, if 
> not impossible. (Maybe I'm wrong?)
>   
I think scalar-array math could be sped up quite a bit.  I haven't done 
much in that area at all.   Right now a lot of setup code is handled 
generically instead of type-specifically like it could be.

> I notice that numpy_array.item() will give me the first element as a 
> normal scalar. Would it be possible for numpy_array.item(N) to return 
> the Nth element of the array as a normal scalar?
>   
Now this is an interesting idea.  It would allow you to by-pass the 
slow-indexing as well as the array scalar computation should you desire 
it.  I like it and am going to add it unless there are convincing 
objections.

-Travis





More information about the Numpy-discussion mailing list