# Is there a function to permute columns or rows of a matrix in place?

**URL:** <https://discourse.julialang.org/t/is-there-a-function-to-permute-columns-or-rows-of-a-matrix-in-place/81667>\
**Category:** General Usage\
**Created:** [May 25, 2022, 5:25pm UTC](https://discourse.julialang.org/t/is-there-a-function-to-permute-columns-or-rows-of-a-matrix-in-place/81667 "2022-05-25T17:25:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [May 25, 2022, 5:25pm UTC](https://discourse.julialang.org/t/is-there-a-function-to-permute-columns-or-rows-of-a-matrix-in-place/81667/1 "2022-05-25T17:25:48Z")

</div>

Slicing works to create a permuted copy. But, is there some way to get the permutation in-place?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [May 25, 2022, 6:00pm UTC](https://discourse.julialang.org/t/is-there-a-function-to-permute-columns-or-rows-of-a-matrix-in-place/81667/2 "2022-05-25T18:00:30Z")

</div>

Linking [this related post](https://discourse.julialang.org/t/permute-multidimensional-array-without-allocation/29153/9).  
For columns it indicates: `Base.permutecols!!(A, p)`  
Should we use for rows: `Base.permutecols!!(A', p)` ?

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [May 25, 2022, 8:09pm UTC](https://discourse.julialang.org/t/is-there-a-function-to-permute-columns-or-rows-of-a-matrix-in-place/81667/3 "2022-05-25T20:09:35Z")

</div>

This is a good find, thanks. (As well as thanks to @stevengj for recalling that bit of code.)  
The matrix is indeed left alone, but there is a work vector that needs to be allocated (i.e. if we need to preserve the pivot vector.).

However, curiously, the time that it takes to do this is about the same for the slicing version and this in-place version.
