I want to modify a dense square transition matrix in-place by changing the order of several of its rows and columns, using python's numpy library. Mathematically this corresponds to pre-multiplying the matrix by the permutation matrix P and post-multiplying it by P^-1 = P^T, but this is not a computationally reasonable solution.
Right now I am manually swapping rows and columns, but I would have expected numpy to have a nice function f(M, v) where M has n rows and columns, and v has n entries, so that f(M, v) updates M according to the index permutation v. Maybe I am just failing at searching the internet.
Something like this might be possible with numpy's "advanced indexing" but my understanding is that such a solution would not be in-place. Also for some simple situations it may be sufficient to just separately track an index permutation, but this is not convenient in my case.
Added:
Sometimes when people talk about permutations, they only mean the sampling of random permutations, for example as part of a procedure to obtain p-values in statistics. Or they mean counting or enumerating all possible permutations. I'm not talking about these things.
Added:
The matrix is small enough to fit into desktop RAM but big enough that I do not want to copy it thoughtlessly. Actually I would like to use matrices as large as possible, but I don't want to deal with the inconvenience of not being able to hold them in RAM, and I do O(N^3) LAPACK operations on the matrix which would also limit the practical matrix size. I currently copy matrices this large unnecessarily, but I would hope this could be easily avoided for permutation.
M[v]
to permute the rows. $\endgroup$