# Rearranging the columns of a matrix [duplicate]

How do I rearrange the columns of a matrix? I really have o idea how to do this. Thankfs for any suggestions!

• What kind of rearrangement did you have in mind? In any event, you could work with the matrix's Transpose[] if need be. – J. M. is in limbo Jun 9 '16 at 10:16
• THanks! I was thinking of something like choosing columns 4,5,7,8,11 in a matrix with more than 11 columns and putting them at the beginning of the matrix. – user40871 Jun 9 '16 at 10:20
• You should have mentioned that in your question to begin with; but, look up Extract[] and Delete[]. Or, multiply your matrix with an appropriately permuted identity matrix. – J. M. is in limbo Jun 9 '16 at 10:24
• In general: mathematica.stackexchange.com/q/3069/5478 – Kuba Jun 9 '16 at 10:33
• With respect to what you want to do, this is already answered in the question Kuba is referring to. See the "swap columns" part – Lukas Jun 9 '16 at 10:39

## 2 Answers

Use Part.

E.g. to exchange row 2 and 3 while also exchanging column 1 and 2 in a 3x3 matrix,

rowOrd = {1,3,2};
colOrd = {2,1,3};
mat[[rowOrd, colOrd]]


Hope the following code could help you:

ord={1,3,5,9,11}
Extract[mat,ord]~Join~Delete[mat,ord]