numpy reverse multidimensional array

How about:

import numpy as np
a = np.array([[[10, 1, 1, 2],
               [2, 2, 2, 3],
               [3, 3, 3, 4]],
              [[1, 1, 1, 2],
               [2, 2, 2, 3],
               [3, 3, 3, 4]]])

and the reverse along the last dimension is:

b = a[:,:,::-1]

or

b = a[...,::-1]

although I like the later less since the first two dimensions are implicit and it is more difficult to see what is going on.

Leave a Comment