[Numpy-discussion] Why multiple ellipses?
Travis Oliphant
oliphant at ee.byu.edu
Fri Feb 24 16:09:01 EST 2006
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.
Thus, only one ellipsis is actually treated like an ellipse. Everything
else is treated as ':'
-Travis
More information about the NumPy-Discussion
mailing list