[SciPy-dev] [Numpy-discussion] Re: How to handle a[...] in numpy?

Travis Oliphant oliphant.travis at ieee.org
Tue Jan 10 10:47:25 EST 2006


Sasha wrote:

>Attached patch implements indexing of zero rank arrays:
>
>  
>
>>>>x = array(42)
>>>>x[...]
>>>>        
>>>>
>42
>  
>
>>>>x[()]
>>>>        
>>>>
>42
>  
>
>>>>x[()].dtype
>>>>        
>>>>
><type 'int32_arrtype'>
>  
>
>>>>type(x[()])
>>>>        
>>>>
><type 'int32_arrtype'>
>
>Ellipsis and empty tuple are the only two valid indices.
>
>So far there was only one +1 vote for the feature (from Francesc
>Altet, who also suggested  that x[()] be allowed).  Does anyone object
>to this feature?
>
>I have also proposed to support x[...,newaxis] (see comment by
>sdementen at http://www.scipy.org/wikis/numdesign/).  I will add this
>feature if there is interest.
>
>Finally, if we make x[...] valid for rank-0 arrays, should x[...] =
>value be allowed as well? I think it should, applying the principle of
>least surprized.  An additional consideration is that rank-0 arrays
>are unhashable, but there is no obvious way to change their values.
>
>The following example show that rank-0 arrays are in fact mutable (in
>a non-obvious way):
>
>  
>
>>>>x = array(1)
>>>>x.shape=(1,); x[0] = 42; x.shape=()
>>>>x
>>>>        
>>>>
>
>  
>
Generally, the array scalars are supposed to replace rank-0 arrays.  
However, this may be too ambitious and as long as the rank-0 arrays are 
there, they may as well be useful.

>Please comment on the following proposals:
>
>1. x[...]
>  
>
+1

>2. x[...] = value
>  
>
+1

>3. x[..., newaxis]
>  
>
+1

>
>  
>




More information about the SciPy-Dev mailing list