numpy reverse multidimensional array
multidimensional-array, numpy, python
Solution
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.
Problem
What is the simplest way in numpy to reverse the most inner values of an array like this: ``` array([[[1, 1, 1, 2], [2, 2, 2, 3], [3, 3, 3, 4]], [[1, 1, 1, 2], [2, 2, 2, 3], [3, 3, 3, 4]]]) ``` so that I get the following result: ``` array([[[2, 1, 1, 1], [3, 2, 2, 2], [4, 3, 3, 3]], [[2, 1, 1, 1], [3, 2, 2, 2], [4, 3, 3, 3]]]) ``` Thank you very much!