[Tutor] What is Ellipsis for?

Roman Suzi rnd@onego.ru
Mon, 27 Aug 2001 13:48:10 +0400 (MSD)


On Mon, 27 Aug 2001, Ignacio Vazquez-Abrams wrote:

> I came across Ellipsis a while ago, and when I did, I just ignored it.
> However, now I just finally have to know: What the hell is it for? I've tried
> reading the last paragraph of section 5.3.3 over and over again and it just
> doesn't make sense now matter how I push it around in the interpreter. Can
> anyone explain its purpose to me please?

Ellipsis is a special object to specify "..." in slices.
It is not used in Python itself but by some extensions, like
Numeric, to specify arbitrary number of dimension indices.

For example:

>>> import Numeric
>>> a = Numeric.array([[1,2],[3,4]])
>>> a[...]
array([[1, 2],
       [3, 4]])
>>> a[...,1]
array([2, 4])
>>>


The object itself could be seen if we create object handling
getslice:

>>> class A:
...   def __getitem__(self, slice): print slice
...
>>> a=A()
>>> a[...]
Ellipsis

Or in newer Python:

Python 2.0 (#1, Oct 16 2000, 18:10:03)
[GCC 2.95.2 19991024 (release)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> class A:
...   def __getitem__(self, x): print x
...
>>> a=A()
>>> a[...]
Ellipsis


Sincerely yours, Roman A.Suzi
-- 
 - Petrozavodsk - Karelia - Russia - mailto:rnd@onego.ru -