title: Permute rows and columns of a matrix
body: <p>Assuming that I have the following matrix/array:</p>
  
  <pre><code>array([[0, 0, 1, 1, 1],
         [0, 0, 1, 0, 1],
         [1, 1, 0, 1, 1],
         [1, 0, 1, 0, 0],
         [1, 1, 1, 0, 0]])
  </code></pre>
  
  <p>and I want to apply the following permutation:</p>
  
  <pre><code>1 -&gt; 5
  2 -&gt; 4
  </code></pre>
  
  <p>the result should be in the end:</p>
  
  <pre><code>array([[1, 1, 1, 0, 0],
         [1, 0, 1, 0, 0],
         [1, 1, 0, 1, 1],
         [0, 0, 1, 0, 1],
         [0, 0, 1, 1, 1]])
  </code></pre>
  
  <p>Now, an incredibly naive (and memory costly) way of doing so might be:</p>
  
  <pre><code>a2 = deepcopy(a1)
  a2[0,:] = a1[4,:]
  a2[4,:] = a1[0,:]
  a = deepcopy(a2)
  a2[:,0] = a[:,4]
  a2[:,4] = a[:,0]
  
  a3 = deepcopy(a2)
  a2[1,:] = a3[3,:]
  a2[3,:] = a3[1,:]
  a = deepcopy(a2)
  a2[:,1] = a[:,3]
  a2[:,3] = a[:,1]
  </code></pre>
  
  <p>But, I would like to know if there is something more efficient that does this. numpy.shuffle and numpy.permutation seem to permute only the rows of the matrix (not the columns at the same time). That doesn't work for me because the matrices are adjacency matrices (representing graphs), and I need to do the permutations which will give me a graph which is isomorphic with the original graph. Furthermore, I need to do an arbitrary number of permutations (more than one).</p>
  
  <p>Thanks!</p>