title: How to permutate rows in sparse (Numpy) matrix efficiently using permutation array?
body: <p>I used the Scipy Reverse Cuthill-McKee implementation (<a href="https://docs.scipy.org/doc/scipy-0.16.1/reference/generated/scipy.sparse.csgraph.reverse_cuthill_mckee.html" rel="nofollow noreferrer">scipy.sparse.csgraph.reverse_cuthill_mckee</a>) for creating a band matrix using a (high-dimensional) sparse csr_matrix.
  The result of this method is a permutation array whichs gives me the indices of how to permutate the rows of my matrix as I understood.</p>
  
  <p>Now is there any efficient solution for doing this permutation on my sparse csr_matrix in any other sparse matrix (csr, lil_matrix, etc)? 
  I tried a for-loop but my matrix has dimension like 200,000 x 150,000 and it takes too much time.</p>
  
  <pre><code>A = csr_matrix((data,(rowind,columnind)), shape=(200000, 150000), dtype=np.uint8)
  
  permutation_array = csgraph.reverse_cuthill_mckee(A, false)
  
  result_matrix = lil_matrix((200000, 150000), dtype=np.uint8)
  
  i=0
  for x in np.nditer(permutation_array):
      result_matrix[x, :]=A[i, :]
      i+=1
  </code></pre>
  
  <p>The result of the reverse_cuthill_mckee call is an array which is like a tupel containing the indices for my permutation. So this array is something like: [199999  54877  54873 ...,   12045   9191      0] (size = 200,000) </p>
  
  <p>This means:
  row with index 0 has now index 199999, 
  row with index 1 has now index 54877, 
  row with index 2 has now index 54873,
  etc. see: <a href="https://en.wikipedia.org/wiki/Permutation#Definition_and_notations" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Permutation#Definition_and_notations</a>
  (As I understood the return)</p>
  
  <p>Thank you</p>