Issue
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!
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.
Answered By - JoshAdel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.