2
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.

Kuba
  • 136,707
  • 13
  • 279
  • 740
santosh
  • 603
  • 3
  • 11

1 Answers1

9

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

Kuba
  • 136,707
  • 13
  • 279
  • 740
  • 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 '14 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 '14 at 05:12