Changing the position of rows and columns in a matrix












2












$begingroup$


I have the following self-explanatory question.



https://1drv.ms/u/s!AsyHs3E_aioxhipb3wSPSX_heN-t



enter image description here



As seen from the above matrices, I start with the "original" matrix, which is a symmetric matrix, meaning that first row and first column represent the same variable, say X, and 2nd row and 2nd column represent the variable Y, following Z, W, V. I first want to move 2nd row in the "original" matrix to 4th row. This operation is shown in the matrix denoted by r24. After this operation, I want to do the same operation on the same columns, meaning that I want to move 2nd column to 4th column as shown in c24. All of these operations are shown with the colored text. The resulting final matrix, which I aim to create, c24, should be symmetric with respect to the variable names. It means that the final matrix has the ordered variable names as X, Z, W, Y, V in columns and rows. In fact, if the above two operations are done correctly, the order of the variables in rows and columns will remain identical.



I like to do all the operations using a Mathematica function such as f[original, 2, 4] to create the final matrix c24.



Thank you all.










share|improve this question











$endgroup$












  • $begingroup$
    closely related/ possible duplicate: Move element inside a list
    $endgroup$
    – kglr
    1 hour ago
















2












$begingroup$


I have the following self-explanatory question.



https://1drv.ms/u/s!AsyHs3E_aioxhipb3wSPSX_heN-t



enter image description here



As seen from the above matrices, I start with the "original" matrix, which is a symmetric matrix, meaning that first row and first column represent the same variable, say X, and 2nd row and 2nd column represent the variable Y, following Z, W, V. I first want to move 2nd row in the "original" matrix to 4th row. This operation is shown in the matrix denoted by r24. After this operation, I want to do the same operation on the same columns, meaning that I want to move 2nd column to 4th column as shown in c24. All of these operations are shown with the colored text. The resulting final matrix, which I aim to create, c24, should be symmetric with respect to the variable names. It means that the final matrix has the ordered variable names as X, Z, W, Y, V in columns and rows. In fact, if the above two operations are done correctly, the order of the variables in rows and columns will remain identical.



I like to do all the operations using a Mathematica function such as f[original, 2, 4] to create the final matrix c24.



Thank you all.










share|improve this question











$endgroup$












  • $begingroup$
    closely related/ possible duplicate: Move element inside a list
    $endgroup$
    – kglr
    1 hour ago














2












2








2


1



$begingroup$


I have the following self-explanatory question.



https://1drv.ms/u/s!AsyHs3E_aioxhipb3wSPSX_heN-t



enter image description here



As seen from the above matrices, I start with the "original" matrix, which is a symmetric matrix, meaning that first row and first column represent the same variable, say X, and 2nd row and 2nd column represent the variable Y, following Z, W, V. I first want to move 2nd row in the "original" matrix to 4th row. This operation is shown in the matrix denoted by r24. After this operation, I want to do the same operation on the same columns, meaning that I want to move 2nd column to 4th column as shown in c24. All of these operations are shown with the colored text. The resulting final matrix, which I aim to create, c24, should be symmetric with respect to the variable names. It means that the final matrix has the ordered variable names as X, Z, W, Y, V in columns and rows. In fact, if the above two operations are done correctly, the order of the variables in rows and columns will remain identical.



I like to do all the operations using a Mathematica function such as f[original, 2, 4] to create the final matrix c24.



Thank you all.










share|improve this question











$endgroup$




I have the following self-explanatory question.



https://1drv.ms/u/s!AsyHs3E_aioxhipb3wSPSX_heN-t



enter image description here



As seen from the above matrices, I start with the "original" matrix, which is a symmetric matrix, meaning that first row and first column represent the same variable, say X, and 2nd row and 2nd column represent the variable Y, following Z, W, V. I first want to move 2nd row in the "original" matrix to 4th row. This operation is shown in the matrix denoted by r24. After this operation, I want to do the same operation on the same columns, meaning that I want to move 2nd column to 4th column as shown in c24. All of these operations are shown with the colored text. The resulting final matrix, which I aim to create, c24, should be symmetric with respect to the variable names. It means that the final matrix has the ordered variable names as X, Z, W, Y, V in columns and rows. In fact, if the above two operations are done correctly, the order of the variables in rows and columns will remain identical.



I like to do all the operations using a Mathematica function such as f[original, 2, 4] to create the final matrix c24.



Thank you all.







matrix






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 hours ago









user64494

3,52811022




3,52811022










asked 5 hours ago









Tugrul TemelTugrul Temel

860213




860213












  • $begingroup$
    closely related/ possible duplicate: Move element inside a list
    $endgroup$
    – kglr
    1 hour ago


















  • $begingroup$
    closely related/ possible duplicate: Move element inside a list
    $endgroup$
    – kglr
    1 hour ago
















$begingroup$
closely related/ possible duplicate: Move element inside a list
$endgroup$
– kglr
1 hour ago




$begingroup$
closely related/ possible duplicate: Move element inside a list
$endgroup$
– kglr
1 hour ago










3 Answers
3






active

oldest

votes


















2












$begingroup$

Simply use Part and Set:



f[A_?SquareMatrixQ, i_Integer, j_Integer] := Module[{p, q, B},
q = Range @@ Sort[{i, j}];
p = RotateLeft[q, -Sign[i - j]];
B = A;
B[[q]] = B[[p]];
B[[All, q]] = B[[All, p]];
B
]

A = Outer[Plus, Range[5], Range[0, 4]];
A // MatrixForm



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




B = f[A,2,4];
B // MatrixForm



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







share|improve this answer











$endgroup$













  • $begingroup$
    Your answer is very good, with one slight change. When you move the 2nd row to 4th row, the order of the rows should remain unchanged. It means that when you move the 2nd row, the 3rd and 4th rows should just be moved up without changing the order. Of course the same applies to the column movements. This is important for my purpose and that is why I gave a name for rows and columns. Thank you very much for your very quick answer.
    $endgroup$
    – Tugrul Temel
    5 hours ago










  • $begingroup$
    @TugrulTemel I see. Is this better now? I am not sure if the case $i>j$ is handled as you expect.
    $endgroup$
    – Henrik Schumacher
    4 hours ago










  • $begingroup$
    Excellent...that is what I aim to achieve. Really, thank you so much for your prompt answer. regards, Tugrul
    $endgroup$
    – Tugrul Temel
    4 hours ago










  • $begingroup$
    You're welcome.
    $endgroup$
    – Henrik Schumacher
    4 hours ago



















1












$begingroup$

to move a row from $i$ to $j$:



rowmove[A_?MatrixQ, i_Integer, j_Integer] := Insert[Delete[A, i], A[[i]], j]


to move a column from $i$ to $j$:



colmove[A_?MatrixQ, i_Integer, j_Integer] := Transpose@rowmove[Transpose[A], i, j]


both at the same time:



move[A_?MatrixQ, i_Integer, j_Integer] := colmove[rowmove[A, i, j], i, j]





share|improve this answer









$endgroup$













  • $begingroup$
    Clean solution, copying it...
    $endgroup$
    – MikeY
    4 hours ago



















0












$begingroup$

Define the indices that you want to interchange in a list $ind$ and then you can index into the array $a$ directly.



a = {{1, 2, 3, 4, 5}, {2, 3, 4, 5, 6}, {3, 4, 5, 6, 7},
{4, 5, 6, 7, 8}, {5, 6, 7, 8, 9}};
ind = {1, 3, 4, 2, 5};
a[[ind, ind]]





share|improve this answer









$endgroup$













    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "387"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f193640%2fchanging-the-position-of-rows-and-columns-in-a-matrix%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2












    $begingroup$

    Simply use Part and Set:



    f[A_?SquareMatrixQ, i_Integer, j_Integer] := Module[{p, q, B},
    q = Range @@ Sort[{i, j}];
    p = RotateLeft[q, -Sign[i - j]];
    B = A;
    B[[q]] = B[[p]];
    B[[All, q]] = B[[All, p]];
    B
    ]

    A = Outer[Plus, Range[5], Range[0, 4]];
    A // MatrixForm



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




    B = f[A,2,4];
    B // MatrixForm



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







    share|improve this answer











    $endgroup$













    • $begingroup$
      Your answer is very good, with one slight change. When you move the 2nd row to 4th row, the order of the rows should remain unchanged. It means that when you move the 2nd row, the 3rd and 4th rows should just be moved up without changing the order. Of course the same applies to the column movements. This is important for my purpose and that is why I gave a name for rows and columns. Thank you very much for your very quick answer.
      $endgroup$
      – Tugrul Temel
      5 hours ago










    • $begingroup$
      @TugrulTemel I see. Is this better now? I am not sure if the case $i>j$ is handled as you expect.
      $endgroup$
      – Henrik Schumacher
      4 hours ago










    • $begingroup$
      Excellent...that is what I aim to achieve. Really, thank you so much for your prompt answer. regards, Tugrul
      $endgroup$
      – Tugrul Temel
      4 hours ago










    • $begingroup$
      You're welcome.
      $endgroup$
      – Henrik Schumacher
      4 hours ago
















    2












    $begingroup$

    Simply use Part and Set:



    f[A_?SquareMatrixQ, i_Integer, j_Integer] := Module[{p, q, B},
    q = Range @@ Sort[{i, j}];
    p = RotateLeft[q, -Sign[i - j]];
    B = A;
    B[[q]] = B[[p]];
    B[[All, q]] = B[[All, p]];
    B
    ]

    A = Outer[Plus, Range[5], Range[0, 4]];
    A // MatrixForm



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




    B = f[A,2,4];
    B // MatrixForm



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







    share|improve this answer











    $endgroup$













    • $begingroup$
      Your answer is very good, with one slight change. When you move the 2nd row to 4th row, the order of the rows should remain unchanged. It means that when you move the 2nd row, the 3rd and 4th rows should just be moved up without changing the order. Of course the same applies to the column movements. This is important for my purpose and that is why I gave a name for rows and columns. Thank you very much for your very quick answer.
      $endgroup$
      – Tugrul Temel
      5 hours ago










    • $begingroup$
      @TugrulTemel I see. Is this better now? I am not sure if the case $i>j$ is handled as you expect.
      $endgroup$
      – Henrik Schumacher
      4 hours ago










    • $begingroup$
      Excellent...that is what I aim to achieve. Really, thank you so much for your prompt answer. regards, Tugrul
      $endgroup$
      – Tugrul Temel
      4 hours ago










    • $begingroup$
      You're welcome.
      $endgroup$
      – Henrik Schumacher
      4 hours ago














    2












    2








    2





    $begingroup$

    Simply use Part and Set:



    f[A_?SquareMatrixQ, i_Integer, j_Integer] := Module[{p, q, B},
    q = Range @@ Sort[{i, j}];
    p = RotateLeft[q, -Sign[i - j]];
    B = A;
    B[[q]] = B[[p]];
    B[[All, q]] = B[[All, p]];
    B
    ]

    A = Outer[Plus, Range[5], Range[0, 4]];
    A // MatrixForm



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




    B = f[A,2,4];
    B // MatrixForm



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







    share|improve this answer











    $endgroup$



    Simply use Part and Set:



    f[A_?SquareMatrixQ, i_Integer, j_Integer] := Module[{p, q, B},
    q = Range @@ Sort[{i, j}];
    p = RotateLeft[q, -Sign[i - j]];
    B = A;
    B[[q]] = B[[p]];
    B[[All, q]] = B[[All, p]];
    B
    ]

    A = Outer[Plus, Range[5], Range[0, 4]];
    A // MatrixForm



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




    B = f[A,2,4];
    B // MatrixForm



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








    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 4 hours ago

























    answered 5 hours ago









    Henrik SchumacherHenrik Schumacher

    57.1k577157




    57.1k577157












    • $begingroup$
      Your answer is very good, with one slight change. When you move the 2nd row to 4th row, the order of the rows should remain unchanged. It means that when you move the 2nd row, the 3rd and 4th rows should just be moved up without changing the order. Of course the same applies to the column movements. This is important for my purpose and that is why I gave a name for rows and columns. Thank you very much for your very quick answer.
      $endgroup$
      – Tugrul Temel
      5 hours ago










    • $begingroup$
      @TugrulTemel I see. Is this better now? I am not sure if the case $i>j$ is handled as you expect.
      $endgroup$
      – Henrik Schumacher
      4 hours ago










    • $begingroup$
      Excellent...that is what I aim to achieve. Really, thank you so much for your prompt answer. regards, Tugrul
      $endgroup$
      – Tugrul Temel
      4 hours ago










    • $begingroup$
      You're welcome.
      $endgroup$
      – Henrik Schumacher
      4 hours ago


















    • $begingroup$
      Your answer is very good, with one slight change. When you move the 2nd row to 4th row, the order of the rows should remain unchanged. It means that when you move the 2nd row, the 3rd and 4th rows should just be moved up without changing the order. Of course the same applies to the column movements. This is important for my purpose and that is why I gave a name for rows and columns. Thank you very much for your very quick answer.
      $endgroup$
      – Tugrul Temel
      5 hours ago










    • $begingroup$
      @TugrulTemel I see. Is this better now? I am not sure if the case $i>j$ is handled as you expect.
      $endgroup$
      – Henrik Schumacher
      4 hours ago










    • $begingroup$
      Excellent...that is what I aim to achieve. Really, thank you so much for your prompt answer. regards, Tugrul
      $endgroup$
      – Tugrul Temel
      4 hours ago










    • $begingroup$
      You're welcome.
      $endgroup$
      – Henrik Schumacher
      4 hours ago
















    $begingroup$
    Your answer is very good, with one slight change. When you move the 2nd row to 4th row, the order of the rows should remain unchanged. It means that when you move the 2nd row, the 3rd and 4th rows should just be moved up without changing the order. Of course the same applies to the column movements. This is important for my purpose and that is why I gave a name for rows and columns. Thank you very much for your very quick answer.
    $endgroup$
    – Tugrul Temel
    5 hours ago




    $begingroup$
    Your answer is very good, with one slight change. When you move the 2nd row to 4th row, the order of the rows should remain unchanged. It means that when you move the 2nd row, the 3rd and 4th rows should just be moved up without changing the order. Of course the same applies to the column movements. This is important for my purpose and that is why I gave a name for rows and columns. Thank you very much for your very quick answer.
    $endgroup$
    – Tugrul Temel
    5 hours ago












    $begingroup$
    @TugrulTemel I see. Is this better now? I am not sure if the case $i>j$ is handled as you expect.
    $endgroup$
    – Henrik Schumacher
    4 hours ago




    $begingroup$
    @TugrulTemel I see. Is this better now? I am not sure if the case $i>j$ is handled as you expect.
    $endgroup$
    – Henrik Schumacher
    4 hours ago












    $begingroup$
    Excellent...that is what I aim to achieve. Really, thank you so much for your prompt answer. regards, Tugrul
    $endgroup$
    – Tugrul Temel
    4 hours ago




    $begingroup$
    Excellent...that is what I aim to achieve. Really, thank you so much for your prompt answer. regards, Tugrul
    $endgroup$
    – Tugrul Temel
    4 hours ago












    $begingroup$
    You're welcome.
    $endgroup$
    – Henrik Schumacher
    4 hours ago




    $begingroup$
    You're welcome.
    $endgroup$
    – Henrik Schumacher
    4 hours ago











    1












    $begingroup$

    to move a row from $i$ to $j$:



    rowmove[A_?MatrixQ, i_Integer, j_Integer] := Insert[Delete[A, i], A[[i]], j]


    to move a column from $i$ to $j$:



    colmove[A_?MatrixQ, i_Integer, j_Integer] := Transpose@rowmove[Transpose[A], i, j]


    both at the same time:



    move[A_?MatrixQ, i_Integer, j_Integer] := colmove[rowmove[A, i, j], i, j]





    share|improve this answer









    $endgroup$













    • $begingroup$
      Clean solution, copying it...
      $endgroup$
      – MikeY
      4 hours ago
















    1












    $begingroup$

    to move a row from $i$ to $j$:



    rowmove[A_?MatrixQ, i_Integer, j_Integer] := Insert[Delete[A, i], A[[i]], j]


    to move a column from $i$ to $j$:



    colmove[A_?MatrixQ, i_Integer, j_Integer] := Transpose@rowmove[Transpose[A], i, j]


    both at the same time:



    move[A_?MatrixQ, i_Integer, j_Integer] := colmove[rowmove[A, i, j], i, j]





    share|improve this answer









    $endgroup$













    • $begingroup$
      Clean solution, copying it...
      $endgroup$
      – MikeY
      4 hours ago














    1












    1








    1





    $begingroup$

    to move a row from $i$ to $j$:



    rowmove[A_?MatrixQ, i_Integer, j_Integer] := Insert[Delete[A, i], A[[i]], j]


    to move a column from $i$ to $j$:



    colmove[A_?MatrixQ, i_Integer, j_Integer] := Transpose@rowmove[Transpose[A], i, j]


    both at the same time:



    move[A_?MatrixQ, i_Integer, j_Integer] := colmove[rowmove[A, i, j], i, j]





    share|improve this answer









    $endgroup$



    to move a row from $i$ to $j$:



    rowmove[A_?MatrixQ, i_Integer, j_Integer] := Insert[Delete[A, i], A[[i]], j]


    to move a column from $i$ to $j$:



    colmove[A_?MatrixQ, i_Integer, j_Integer] := Transpose@rowmove[Transpose[A], i, j]


    both at the same time:



    move[A_?MatrixQ, i_Integer, j_Integer] := colmove[rowmove[A, i, j], i, j]






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 4 hours ago









    RomanRoman

    3,300819




    3,300819












    • $begingroup$
      Clean solution, copying it...
      $endgroup$
      – MikeY
      4 hours ago


















    • $begingroup$
      Clean solution, copying it...
      $endgroup$
      – MikeY
      4 hours ago
















    $begingroup$
    Clean solution, copying it...
    $endgroup$
    – MikeY
    4 hours ago




    $begingroup$
    Clean solution, copying it...
    $endgroup$
    – MikeY
    4 hours ago











    0












    $begingroup$

    Define the indices that you want to interchange in a list $ind$ and then you can index into the array $a$ directly.



    a = {{1, 2, 3, 4, 5}, {2, 3, 4, 5, 6}, {3, 4, 5, 6, 7},
    {4, 5, 6, 7, 8}, {5, 6, 7, 8, 9}};
    ind = {1, 3, 4, 2, 5};
    a[[ind, ind]]





    share|improve this answer









    $endgroup$


















      0












      $begingroup$

      Define the indices that you want to interchange in a list $ind$ and then you can index into the array $a$ directly.



      a = {{1, 2, 3, 4, 5}, {2, 3, 4, 5, 6}, {3, 4, 5, 6, 7},
      {4, 5, 6, 7, 8}, {5, 6, 7, 8, 9}};
      ind = {1, 3, 4, 2, 5};
      a[[ind, ind]]





      share|improve this answer









      $endgroup$
















        0












        0








        0





        $begingroup$

        Define the indices that you want to interchange in a list $ind$ and then you can index into the array $a$ directly.



        a = {{1, 2, 3, 4, 5}, {2, 3, 4, 5, 6}, {3, 4, 5, 6, 7},
        {4, 5, 6, 7, 8}, {5, 6, 7, 8, 9}};
        ind = {1, 3, 4, 2, 5};
        a[[ind, ind]]





        share|improve this answer









        $endgroup$



        Define the indices that you want to interchange in a list $ind$ and then you can index into the array $a$ directly.



        a = {{1, 2, 3, 4, 5}, {2, 3, 4, 5, 6}, {3, 4, 5, 6, 7},
        {4, 5, 6, 7, 8}, {5, 6, 7, 8, 9}};
        ind = {1, 3, 4, 2, 5};
        a[[ind, ind]]






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 3 hours ago









        bill sbill s

        54.4k377156




        54.4k377156






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Mathematica Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f193640%2fchanging-the-position-of-rows-and-columns-in-a-matrix%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)