sorting arrays in numpy by row
<p>I would like to sort an array in numpy by the first row.</p>

<p>For example :</p>

<pre><code>import numpy as np

test = np.array([[1334.71601720318, 930.9757468052002, 1018.7038817663818],
       [0.0, 1.0, 2.0],
       [ np.array([[ 667, 1393],
       [1961,  474]]),
        np.array([[ 673, 1389],
       [ 847, 1280]]),
        np.array([[ 726, 1077],
       [ 898,  961]])]], dtype=object)
</code></pre>

<p>I want to sort the row :</p>

<pre><code>[1334.71601720318, 930.9757468052002, 1018.7038817663818]
</code></pre>

<p>to obtain : </p>

<pre><code>np.array([[930.9757468052002, 1018.7038817663818, 1334.71601720318],
       [1.0, 2.0 ,0.0],
       [ np.array([[ 673, 1389],
       [ 847, 1280]]),
       np.array([[ 726, 1077],
       [ 898,  961]])],
       np.array([[ 667, 1393],
       [1961,  474]])], dtype=object)
</code></pre>

<p>---- EDIT LATER ----</p>

<p>I tried with : sorted(test, key=lambda row: row[1])
But i got an error message : "The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"</p>

<p>I think <code>test[:, np.argsort( test[0] ) ]</code> should do the trick.</p>

python sorting numpy scipy