title: numpy: applying argsort to an array
body: <p>The <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.argsort.html#numpy.argsort" rel="noreferrer"><code>argsort()</code></a> function returns a matrix of indices that can be used to index the original array so that the result would match the <code>sort()</code> result.</p>
  
  <p>Is there a way to apply those indices? I have two arrays, one is the array used for obtaining the sort order, and another is some associated data. </p>
  
  <p>I would like to compute <code>assoc_data[array1.argsort()]</code> but that doesn't seem to work.</p>
  
  <p>Here's an example:</p>
  
  <pre><code>z=array([1,2,3,4,5,6,7])
  z2=array([z,z*z-7])
  i=z2.argsort()
  </code></pre>
  
  <hr>
  
  <pre><code>z2=array([[ 1,  2,  3,  4,  5,  6,  7],
            [-6, -3,  2,  9, 18, 29, 42]])
  i =array([[1, 1, 1, 0, 0, 0, 0],
            [0, 0, 0, 1, 1, 1, 1]])
  </code></pre>
  
  <p>I would like to apply i to z2 (or another array with associated data) but I'm not sure how to do so.    </p>