7

And what is it called? I don't know how to search for it; I tried calling it ellipsis with the Google. I don't mean in interactive output when dots are used to indicate that the full array is not being shown, but as in the code I'm looking at,

xTensor0[...] = xVTensor[..., 0]

From my experimentation, it appears to function the similarly to : in indexing, but stands in for multiple :'s, making x[:,:,1] equivalent to x[...,1].

Thomas
  • 6,515
  • 1
  • 31
  • 47
  • 3
    Check out http://stackoverflow.com/questions/772124/what-does-the-python-ellipsis-object-do and http://stackoverflow.com/questions/118370/how-do-you-use-the-ellipsis-slicing-syntax-in-python – Sam Dolan Oct 22 '10 at 00:52
  • great, wasn't able to search for it. – Thomas Oct 22 '10 at 00:54
  • 1
    Ha, but it's called "ellipsis," so I ought to have been able to. I gave up early when "python numpy ..." didn't work. Thanks sdolan. – Thomas Oct 22 '10 at 01:00
  • 1
    Also, now I can't find a combination of sensible words to search for that doesn't bring up useful Google results for this topic, so apologies all. – Thomas Oct 22 '10 at 01:08

3 Answers3

7

Yes, you're right. It fills in as many : as required. The only difference occurs when you use multiple ellipses. In that case, the first ellipsis acts in the same way, but each remaining one is converted to a single :.

ars
  • 120,335
  • 23
  • 147
  • 134
3

Although this feature exists mainly to support numpy and other, similar modules, it's a core feature of the language and can be used anywhere, like so:

>>> class foo:
...   def __getitem__(self, key):
...     return key
... 
>>> aFoo = foo()
>>> aFoo[..., 1]
(Ellipsis, 1)
>>> 

or even:

>>> derp = {}
>>> derp[..., 1] = "herp"
>>> derp
{(Ellipsis, 1): 'herp'}
SingleNegationElimination
  • 151,563
  • 33
  • 264
  • 304
0

Documentation here: http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html

It does, well, what you describe it doing.

Winston Ewert
  • 44,070
  • 10
  • 68
  • 83