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.

If I have an array like the following

$\left( \begin{array}{ccc} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{array} \right)$

How can I swap the rows and columns, so it is transformed into this?

$\left( \begin{array}{ccc} 1 & 4 & 7 \\ 2 & 5 & 8 \\ 3 & 6 & 9 \end{array} \right)$

This question touches upon the subject, but rather than swapping it simply rotates the matrix.

share|improve this question

closed as off-topic by Kuba, halirutan, bobthechemist, belisarius, Jens May 27 at 17:10

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Kuba, halirutan, bobthechemist, belisarius, Jens
If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Take a look at Transpose. –  Kuba May 27 at 16:42
    
And for more general matrix operations see here –  bobthechemist May 27 at 17:00
    
You need to be familiar with the mathematical term to know what to search for: en.wikipedia.org/wiki/Matrix_transpose –  Szabolcs May 27 at 17:47

1 Answer 1

up vote 0 down vote accepted
m = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};


mt = Transpose[m]

(*
{{1, 4, 7}, {2, 5, 8}, {3, 6, 9}}
*)
share|improve this answer

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