A = np.random.random((2, 4, 3, 5))
C = A.swapaxes(0, 2).swapaxes(1, 3)
C.shape
all(C[k, l, i, j] == A[i, j, k, l] for i, j, k, l in product(*map(range, A.
    shape)))
Swapping the dimensions of a numpy array