[Python-3000] Ellipsis Literal
Robert Kern
robert.kern at gmail.com
Wed Jan 23 08:37:40 CET 2008
Raymond Hettinger wrote:
> I missed the conversation on this one.
> Was there a use case or a reason to add this?
It was added for Numeric a long time ago. We use it in multidimensional indices
to specify slice(None, None, None) for all of the omitted dimensions. For example:
In [25]: from numpy import *
In [26]: a = arange(2*3*4).reshape([2,3,4])
In [27]: a
Out[27]:
array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]],
[[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]]])
In [28]: a[...,0]
Out[28]:
array([[ 0, 4, 8],
[12, 16, 20]])
In [29]: a[:,:,0]
Out[29]:
array([[ 0, 4, 8],
[12, 16, 20]])
In [30]: a[1,...]
Out[30]:
array([[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]])
In [31]: a[1,:,:]
Out[31]:
array([[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]])
In [32]: a[1,...,0]
Out[32]: array([12, 16, 20])
In [33]: a[1,:,0]
Out[33]: array([12, 16, 20])
> I ask because the spelling has an unfortunate
> overlap with the sys.ps2 prompt:
>
>>>> def f(x):
> ... return x+1
>
> I don't know if this is a problem. Just thought I would bring it up.
I've never encountered a problem with this ambiguity. At least, not in software.
I don't know if affects newbie-comprehension of code snippets.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-3000
mailing list