m={{a, b, c, p}, {d, e, f, x}, {g, h, k, z}, {u, v, w, y}};
I want to swap 1st and 2nd rows by 4th and 3rd rows respectively. And then, swap 1st and 2nd columns by 4th and 3rd columns.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityOK, encouraged by belisarius, here's the way.
If you know that Reverse
exists you may use:
Reverse /@ Reverse @ m
then you could check the docs and realise that Reverse
has 2nd argument:
Reverse[m, {1, 2}]
But if you don't but you are amazed by Span
+Part
you can end up with:
m[[;; , {4, 3, 2, 1}]][[{4, 3, 2, 1}]]
or even more Span
: :)
m[[;; , -1 ;; 1 ;; -1]][[-1 ;; 1 ;; -1]]
Why is multidimensional Reverse slow? - nice question where I've learned about -1;;1;;-1
Reverse[m, {1, 2}]
. Related: (2546) and (19726) $\endgroup$Reverse
has second argument, but if you need to reverse something it is easy to face it in docs :) So my point is that it should be closed, but let's see what community says :) $\endgroup$