[Numpy-discussion] Why multiple ellipses?
Paul Barrett
pebarrett at gmail.com
Sat Feb 25 09:57:02 EST 2006
On 2/24/06, Travis Oliphant <oliphant at ee.byu.edu> wrote:
>
> Sasha wrote:
>
> >Numpy allows multiple ellipses in indexing expressions, but I am not
> >sure if that is useful. AFAIK, ellipsis stands for "as many :'s as
> >needed", but if there is more than one, how do I know how many :'s
> >each of them represents:
> >
> >
> It should be that the first ellipsis is interpreted as an ellipsis. Any
> others are silently converted to ':' characters.
>
> >
> >
> >>>>x = arange(8)
> >>>>x.shape=(2,2,2)
> >>>>x[0,...,0,...]
> >>>>
> >>>>
> >array([0, 1])
> >
> >
> This is equivalent to
>
> x[0,...,0,:]
>
> which is equivalent to
>
> x[0,0,:] (because the ellipsis is interpreted as nothing).
>
> >>>>x[0,0,:]
> >>>>
> >>>>
> >array([0, 1])
> >
> >
> >>>>x[0,:,0]
> >>>>
> >>>>
> >array([0, 2])
> >
> >In the example above, the first ellipsis represents no :'s and the
> >last one represents one. Is that the current rule that the last
> >ellipsis represents all the needed :'s? What is the possible use for
> >that?
> >
> >
> >
> The rule is that only the first ellipsis (from left to right) is used
> and any others are just another spelling of ':'.
>
> This is the rule that Numeric implemented and so it's what we've kept.
> I have no idea what the use might be, but I saw changing the rule as
> gratuitous breakage.
This might be a good time to change this behavior, since I've yet to find a
good reason for keeping it. Maybe we can depricate it until version 1.0.
-- Paul
Thus, only one ellipsis is actually treated like an ellipse. Everything
> else is treated as ':'
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060225/efcf5dbd/attachment.html>
More information about the NumPy-Discussion
mailing list