def index_along_axis(index, ndim, axis):
 indices = ([slice(None)] * ndim)
 indices[axis] = index
 return tuple(indices)

def index_along_axis ( index , ndim , axis ) : indices = ( [ slice ( None ) ] * ndim ) indices [ axis ] = index return tuple ( indices )
create a slice tuple for indexing into a numpy array along a given axis .