On Thu, May 20, 2021 at 3:03 PM Ethan Furman <ethan@stoneleaf.us> wrote:
 > But it nevertheless feels like a bit of an abuse - the original point
 > of ellipsis was for indexing, and in particular complex slices like
 > a[1:20:2, ..., 3:5]. That usage is common in numpy, as I understand
 > it,
Interesting -- do you know what ... means in that context?
 
In NumPy, the ellipsis means "fill in as many dimensions as needed (with full range)". 

So e.g., if I have a 5-D array, and I want just a portion from the first and last dimension (but everything from the middle ones), I can type:

    a[1:20:2, :, :, :, 3:5]

But as a simplification, I can use the example given:

    a[1:20:2, ..., 3:5]

This is particularly useful since in NumPy it is not uncommon to expand or contract the number of dimensions (often with some dimensions having only a span of 1).  If you don't want to think about which version of the high-dimensional array you are working with (that might have been .flatten()'d, .squeeze()'d, or .expand_dims()'d), this is sometimes more expressive.


--
The dead increasingly dominate and strangle both the living and the
not-yet born.  Vampiric capital and undead corporate persons abuse
the lives and control the thoughts of homo faber. Ideas, once born,
become abortifacients against new conceptions.