title: Read values of an (M,N) image from a (2,MN) matrix in python
body: <p>Suppose that I have an (M,N) image J (with shape (M,N,3)). And I have a (2,MN) matrix K like this:</p>
  
  <pre><code>0 0 0 ... 0 1 1 1 ... 1 ............. M M M ... M
  
  0 1 2 ... N 1 2 3 ... N ............. 1 2 3 ... N
  </code></pre>
  
  <p>Now I multiply the above matrix by a 2 by 2 matrix to get a new matrix T of the same size as K.</p>
  
  <p>Now I want to create a new image where the pixel (r,s) in this new image is equal to the (R,G,B) value of the pixel of the old image which is in the r*N+M column of T. </p>
  
  <p>I want to do this in a vectorized way if possible. I do not want to use for-loops (I already know how to do this using for-loops, but it's extremely slow). In fact, my interest in this problem is because I want to apply a homography transformation in a vectorized way.</p>
  
  <p>Any help is appreciated. Here's the loopy version for making what I want clear:</p>
  
  <pre><code>for r in range(0,M):
      for s in range(0,N):
          x, y = T[:,r*N+s]
          new_image[r,s] = J[x,y]
  </code></pre>