title: How to efficiently apply an arbitrary remapping to a matrix in Python
body: <p>I want to remap a matrix in Python 2.7, but the reordering pattern doesn't follow simple rules. I have a (192,1024) numpy source array to start with, and want to get a (768,250) target array in the end. Note that some of the colums are dumped in the process, and the resulting array has fewer elements than the original one. Furthermore, rows and colums are scrambled. I created a <a href="https://www.mpp.mpg.de/~valentan/testmap/testmap_stackoverflow.py" rel="nofollow">minimal working example</a> which does what I want, please note how the columns 62 and 187 of the target array are interleaved.</p>
  
  <p>Now I am looking for a way to make the conversion faster. Up to now I came up with two ideas:</p>
  
  <ol>
  <li>A mapping matrix with the same size as the source array, which contains tuples with the target coordinates</li>
  <li>A mapping dictionary whose keys contain the source coordinates, and whose values contain the target coordinates</li>
  </ol>
  
  <p>The minimal example also creates the mapping matrix and the mapping dictionary, but I don't know how to proceed. What would be the most efficient way to apply this quite arbitrary mapping? I am grateful for any tip!</p>