[Numpy-discussion] edge-cases of ellipsis indexing

Antony Lee antony.lee at berkeley.edu
Mon Jan 5 20:53:30 EST 2015


I see, thanks!

2015-01-05 2:14 GMT-07:00 Sebastian Berg <sebastian at sipsolutions.net>:

> On Mo, 2015-01-05 at 14:13 +0530, Maniteja Nandana wrote:
> > Hi Anthony,
> >
> >
> > I am not sure whether the following section in documentation is
> > relevant to the behavior you were referring to.
> >
> >
> > When an ellipsis (...) is present but has no size (i.e. replaces
> > zero :) the result will still always be an array. A view if no
> > advanced index is present, otherwise a copy.
> >
>
> Exactly. There are actually three forms of indexing to distinguish.
>
> 1. Indexing with integers (also scalar arrays) matching the number of
> dimensions. This will return a *scalar*.
> 2. Slicing, etc. which returns a view. This also occurs as soon there is
> an ellipsis in there (even if it replaces 0 `:`). You should see it as a
> feature to get a view if the result might be a scalar otherwise ;)!
> 3. Advanced indexing which cannot be view based and returns a copy.
>
> - Sebastian
>
>
> > Here, ...replaces zero :
> >
> >
> >
> > Advanced indexing always returns a copy of the data (contrast with
> > basic slicing that returns a view).
> > And I think it is a view that is returned in this case.
> >
> >
> > >>> a = array([1])
> > >>>a
> > array([1])
> > >>>a[:,0]  # zero  : are present
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in <module>
> > IndexError: too many indices for array
> > >>>a[...,0]=2
> > >>>a
> > array([2])
> > >>>a[0] = 3
> > >>>a
> > array([3])
> > >>>a[(0,)] = 4
> > >>>a
> > array([4])
> > >>>a[:
> > array([1])
> >
> >
> > Hope I helped.
> >
> >
> > Cheers,
> > N.Maniteja.
> > _______________________________________________
> > NumPy-Discussion mailing list
> > NumPy-Discussion at scipy.org
> > http://mail.scipy.org/mailman/listinfo/numpy-discussion
> >
> >
> >
> > _______________________________________________
> > NumPy-Discussion mailing list
> > NumPy-Discussion at scipy.org
> > http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150105/91938848/attachment.html>


More information about the NumPy-Discussion mailing list