Given a numpy array and a __getitem__-type index, is there an idiomatic way to get the corresponding slice of the array, that would always return an array and never a scalar?
Examples of valid indices include: an int, a slice, an ellipsis or a tuple of the above.
Say I have an array like this:
a = np.array([[1,2],[3,4]])
I am looking for an operation that would be equivalent to a[whatever] in all cases except when a[whatever] returns a scalar (for example, a[1,1]). In those cases I'd like this alternative operation to return a single-element array instead.
numpy.atleast_2dinside atableclass that I wrote myself that mirrored many ofarraymethods. It would probably break all kinds of stuff if you were able to getatleast_*Dbehavior out of a numpy array.atleast_Ndisn't good enough - probably need to convert theintindices toslices.