Numpy multidimensional array slicing Numpy multidimensional array slicing numpy numpy

Numpy multidimensional array slicing


you can create the index tuple first:

index = (numpy.s_[:],)+t x[index]


HYRY solution is correct, but I have always found numpy's r_, c_ and s_ index tricks to be a bit strange looking. So here is the equivalent thing using a slice object:

x[(slice(None),) + t]

That single argument to slice is the stop position (i.e. None meaning all in the same way that x[:] is equivalent to x[None:None])