Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.
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.

share|improve this question
2  
Reverse[m, {1, 2}]. Related: (2546) and (19726) –  Kuba Apr 29 at 15:52
    
I don't think it is obvious that 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 :) –  Kuba Apr 29 at 16:03
2  
@Kuba Unless it's a dup (I don't know), I think you could post it as an answer –  belisarius Apr 29 at 16:07
    
Also related: (3069) and (20228) –  Mr.Wizard Apr 29 at 23:33

1 Answer 1

up vote 9 down vote accepted

OK, 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

share|improve this answer
1  
Congratulations on joining the 20K club! :-) For some reason I still think of you as a "new" member but you have become a pillar of the community, and not by "reputation" alone. –  Mr.Wizard Apr 29 at 23:35
    
@Mr.Wizard Thank you for those kind words :) I do enjoy being here :), almost each day I can learn, or at least face, something new so thank you community of Mathematica.SE :) –  Kuba Apr 30 at 5:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.