title: How to sort each row of a 3D numpy array by another 2D array?
body: <p>I have a 2D numpy array of 2D points:</p>
  <pre><code>np.random.seed(0)   
  a = np.random.rand(3, 4, 2) # each value is a 2D point
  </code></pre>
  <p>I would like to sort each row by the norm of every point</p>
  <pre><code>norms = np.linalg.norm(a, axis=2) # shape(3, 4)
  
  indices = np.argsort(norms, axis=0) # indices of each sorted row
  </code></pre>
  <p>Now I would like to create an array with the same shape and values as <code>a</code>. that will have each row of 2D points sorted by their norm.</p>
  <p>How can I achieve that?</p>
  <p>I tried variations of np.take &amp; np.take_along_axis but with no success.</p>
  <p>for example:</p>
  <pre><code>np.take(a, indices, axis=1) # shape (3,3,4,2)
  </code></pre>
  <p>This samples <code>a</code> 3 times, once for each row in <code>indices</code>.
  I would like to sample <code>a</code> just once. each row in <code>indices</code> has the columns that should be sampled from the corresponding row.</p>