Shuffling the columns of a matrix

949 Views Asked by At

Suppose I have an $N\times k$ matrix:

$$\begin{bmatrix}a_{1,1} & \cdots & a_{N,1} \\ \vdots & \ddots & \vdots \\ a_{1,k} & \cdots & a_{N,k} \end{bmatrix}$$

Is there a stateless function (or algorithm) that will shuffle the $k$ elements in each column randomly, while preserving the columns?

For example, if $N=2$ and $k=3$, we could have:

$$\begin{bmatrix}a_{1,1} & a_{2,1} \\ a_{1,2} & a_{2,2} \\ a_{1,3} & a_{2,3} \end{bmatrix} \mapsto \begin{bmatrix}a_{1,1} & a_{2,3} \\ a_{1,3} & a_{2,1} \\ a_{1,2} & a_{2,2} \end{bmatrix}$$


EDIT By "stateless", I suppose I really mean something like "deterministic while not relying on external state". I'm thinking of this from a computer science perspective, to resolve the contradiction of "random" and "deterministic"; that is, a function that takes a seed -- i.e., for a random number generator -- as its argument. (The input matrix is always the same, so I guess it's not needed as input.)

1

There are 1 best solutions below

5
On BEST ANSWER

Let $P_{ij}$ be the permutation matrix that exchanges row $i$ with row $j$. Then you can exchange column $i$ with column $j$ by applying the associated permutation matrix to the transpose of your matrix, then transposing back: