[Numpy-discussion] Response to PEP suggestions

Travis Oliphant oliphant at ee.byu.edu
Thu Feb 17 12:27:17 EST 2005


Jeff Whitaker wrote:

> >>> from Numeric import *
> >>> a = reshape(arange(9),(3,3))
> >>> print a
> [[0 1 2]
> [3 4 5]
> [6 7 8]]
> >>> a[1]
> array([3, 4, 5])
> >>> a.flat[1]
> 1
>
> so a[K] and a.flat[K] are very different things for multidimensional 
> arrays.  I think it would be a bad idea to change this now - it would 
> certainly break a lot of my code.

>
> Or are you only talking about the case when K is a rank-1 index array 
> and not a scalar?

a[scalar] will behave exactly the same as now.

We are just talking about the case where K is an index array (I should 
clarify that it must be rank-1 or bigger so that K being a rank-0 array 
wold behave just like the a[scalar] case).

This is basically new behavior that numarray has started supporting.  I 
just think numarray missed an important case of flattened indexing that 
MATLAB supports.  My current proposal would distinguish between 
single-index array cases and tuple-index array cases. 

I'm still thinking about the X.flat possibility.  Basically, I think 
that direction would requires a new "generic array view" or something 
like that.  It may be worth trying, but I'm not sure I want to go that 
direction right now until I convince more people to come on board with 
Numeric3.

-Travis






More information about the NumPy-Discussion mailing list