[Numpy-discussion] Accessing rank-0 array value?

Benjamin M. Schwartz bens at MIT.EDU
Tue Jun 8 09:08:03 EDT 2004


Francesc Alted wrote:

>For me, the basic problem is that a[()] notation would be the best way to
>get the python object with a type close to that of the numarray object. Why
>not letting a[...] or a[:] to return the same object as a[()]?. I know that
>this is not consistent with the "..." or ":" use in non-scalar arrays, but I
>find any of last two far more intuitive than a "()" index. 
>  
>
I don't agree with this idea as written; I think that a[:] should always 
return a.  However, I think that there is another relevant point here: 
single-element arrays have no rank!
In other words, from a purely mathematical point of view, it makes sense 
not to distinguish between the number 5, the vector with a single 
element 5, the 1x1 matrix 5, the 1x1x1 object-of-some-sort 5, etc.

Accordingly, if a is a single-element array, it would be sensible for 
a[()]==a[0]==a[0,0]==a[0,0,0]==a[(0)]==a[(0, 0, 0, 0, 0)]

Asking for the array's dimensions would then require a convention.

-long-time-reader, first-time-poster

Ben Schwartz




More information about the NumPy-Discussion mailing list