With A a Numpy ndarray, is there a generic way to implement this code in a single line and without testing the dimension of A (assumed equal to 2 or 3)?
if len(A.shape) == 2: B = A[st[0]:ed[0], st[1]:ed[1]]
else: B = A[st[0]:ed[0], st[1]:ed[1], st[2]:ed[2]]