Search code examples
pythonnumpysliceellipsis

How slicing and ellipsis works in numpy?


I have been reading a very old documentation of Numpy and found out a weird notation which eludes my understanding. The documentation says a[i:...] is a shortcut for a[i,:,:,:].

The documentation being old is very vague and I would welcome any comments.

Thanks, Prerit


Solution

  • Three full stops ... (and not (U+2026)), refers to the Ellipsis singleton object. It has no built-in special operations but is often used in slicing expressions.

    No built-in classes utilise the Ellipsis object however NumPy uses ... as a shortcut when slicing arrays, for example, where x is a 4D array: x[i, ...] is equivalant to x[i, :, :, :].

    NumPy - Indexing