# Symmetrically permute a matrix

**URL:** <https://discourse.julialang.org/t/symmetrically-permute-a-matrix/80537>\
**Category:** General Usage\
**Tags:** question, linearalgebra, arrays\
**Created:** [May 5, 2022, 11:35am UTC](https://discourse.julialang.org/t/symmetrically-permute-a-matrix/80537 "2022-05-05T11:35:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![psanan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/psanan/32/30106_2.png) [@psanan](https://discourse.julialang.org/u/psanan)\
**Post date:** [May 5, 2022, 11:35am UTC](https://discourse.julialang.org/t/symmetrically-permute-a-matrix/80537/1 "2022-05-05T11:35:57Z")

</div>

I’d like to symmetrically permute a matrix. For example, I want to transform

\left[\begin{array}{ccc} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9\end{array}\right]

by rearranging the rows and columns according to the permuation [3, 1, 2], to get

\left[\begin{array}{ccc} 9 & 7 & 8 \\ 3 & 1 & 2 \\ 7 & 4 & 5\end{array}\right]

In MATLAB I’d do

```
p = [3 1 2]
A = [1 2 3; 4 5 6; 7 8 9]
A_permuted = A(p, p)

```

How do I do it with Julia?

---

<div class="post-metadata">

**Author:** ![jacobusmmsmit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacobusmmsmit/32/217669_2.png) [@jacobusmmsmit](https://discourse.julialang.org/u/jacobusmmsmit)\
**Post date:** [May 5, 2022, 11:39am UTC](https://discourse.julialang.org/t/symmetrically-permute-a-matrix/80537/2 "2022-05-05T11:39:38Z")

</div>

The (almost) exact same code:

```julia
p = [3, 1, 2] # comma separated so this is a vector as opposed to a 1x3 Matrix
A = [1 2 3; 4 5 6; 7 8 9]
A_permuted = A[p, p]

```
