How do you use the ellipsis slicing syntax in Python?
Question: This came up in [Hidden features of
Python](http://stackoverflow.com/questions/101268/hidden-features-of-python),
but I can't see good documentation or examples that explain how the feature
works.


Answer: The ellipsis is used to slice higher-dimensional data structures.

It's designed to mean _at this point, insert as many full slices (`:`) to
extend the multi-dimensional slice to all dimensions_.

**Example** :

    
    
    >>> from numpy import arange
    >>> a = arange(16).reshape(2,2,2,2)
    

Now, you have a 4-dimensional matrix of order 2x2x2x2. To select all first
elements in the 4th dimension, you can use the ellipsis notation

    
    
    >>> a[..., 0].flatten()
    array([ 0,  2,  4,  6,  8, 10, 12, 14])
    

which is equivalent to

    
    
    >>> a[:,:,:,0].flatten()
    array([ 0,  2,  4,  6,  8, 10, 12, 14])
    

In your own implementations, you're free to ignore the contract mentioned
above and use it for whatever you see fit.

