2.17 Swap 2 columns in a matrix
Give a matrix
1 2
3 4
5 6
How to change it so that the second column becomes the first, and the first becomes the
second? so that the result become
2 1
4 3
6 5
| Mathematica
a={{1,2},
{3,4},
{5,6}}
Reverse[a,2]
|
Out[29]= {{2, 1},
{4, 3},
{6, 5}}
|
| Matlab
a =[1 2;
3 4;
5 6]
[a(:,2) a(:,1)]
|
2 1
4 3
6 5
|
| Maple
A:=Matrix([[1,2],[3,4],[5,6]]);
A:=Matrix([ A[..,2], A[..,1] ])
|
[[2,1],
[4,3],
[6,5]]
|