Sorting a numpy array based on data from another array
<p>I have two sets of array <code>data</code> and <code>result</code>. <code>result</code> contains the same elements in <code>data</code> but with an extra column and in unsorted order. I want to rearrange the <code>result</code> array so that it is in the same order as the rows in <code>data</code> , while bringing the associated value into the last column with the rest of the row when doing the sorting.</p>

<pre><code>data = np.array([[0,1,0,0],[1,0,0,0],[0,1,1,0],[0,1,0,1]])
result = np.array([[0,1,1,0,1],[1,0,0,0,0],[0,1,0,0,1],[0,1,0,1,0]])

# this is what the final sorted array should look like:
'''
array([[0, 1, 0, 0, 1],
       [1, 0, 0, 0, 0],
       [0, 1, 1, 0, 1],
       [0, 1, 0, 1, 0]])
 '''
</code></pre>

<p>I've tried doing <code>argsort</code> in order to reverse <code>data</code> into the sorted order then applying that to <code>result</code> but <code>argsort</code> seems to sort the order of the array based on each element, whereas I want the sort to treat each row of the <code>data[:,4]</code> as a whole.</p>

<pre><code>ind = np.argsort(data)
indind =np.argsort(ind)
ind
array([[0, 2, 3, 1],
   [1, 2, 3, 0],
   [0, 3, 1, 2],
   [0, 2, 1, 3]])
</code></pre>

<p>What is a good way to do this kind of sorting by rows? </p>