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

Francesc Altet faltet at carabos.com
Mon Jan 9 11:04:08 EST 2006


A Dilluns 09 Gener 2006 19:19, Sasha va escriure:
> On 1/9/06, Francesc Altet <faltet at carabos.com> wrote:
> > ...
> > I'd propose the next behaviour for 0-rank arrays:
> >
> > In [65]: type(numpy.array(0)[...])
> > Out[65]: <type 'numpy.ndarray'>
> >
> > In [66]: type(numpy.array(0)[()])   # Indexing a la numarray
> > Out[66]: <type 'int32_arrtype'>
>
> I like the idea of supporting [()] on zero rank ndarrays, but I think
> it should be equivalent to [...].  I view [...] as [(slice(None),) *
> rank], and thus for rank=0, [...] is the same as [()].

However, the original aim of the "..." (ellipsis) operator is [taken
for the numarray manual]:

"""
One final way of slicing arrays is with the keyword `...' This keyword
is somewhat complicated. It stands for "however many `:' I need
depending on the rank of the object I'm indexing, so that the indices
I do specify are at the end of the index list as opposed to the usual
beginning".

So, if one has a rank-3 array A, then A[...,0] is the same thing as
A[:,:,0], but if B is rank-4, then B[...,0] is the same thing as:
B[:,:,:,0]. Only one `...' is expanded in an index expression, so if
one has a rank-5 array C, then C[...,0,...] is the same thing as
C[:,:,:,0,:].
"""

> Furthermore, I don't see any use for [...] that always returns the
> same array.  As far as I remember in some old version of Numeric,
> [...] was a way to make a contiguous copy, but in numpy this is not
> the case (one needs to use copy method for that).

I don't know for old versions of Numeric, but my impression is that
the ellipsis meaning is clearly stated above. In fact, in a
4-dimensional array, say a, a[...] should be equivalent to a[:,:,:,:]
and this does not necessarily implies a copy.

Cheers,

-- 
>0,0<   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data
 "-"






More information about the NumPy-Discussion mailing list