The difference is that the first examples trigger fancy indexing (which simply selects indexes on the list from the same size), while tuple_index[:31] instead treated as an indexing tuple (which implies choosing from multiple axes).
As you noted, the maximum number of dimensions for a NumPy array is (usually) 32:
>>> np.MAXDIMS 32
According to the following comment in the mapping.c file (which contains code for interpreting the index passed by the user), any sequence of tuples shorter than 32 is smoothed out with an index tuple:
(I have not yet found a link for this in the official documentation on the SciPy website.)
This makes a[tuple_index[:3]] equivalent to a[(0,), (1,), (2,)] , so the error is βtoo many indexesβ (because a has only one dimension, but we mean that there are three of them).
On the other hand, a[tuple_index] matches a[[(0,), (1,), (2,), ..., (99,)]] , which leads to a 2D array.
Alex Riley
source share