snipt

Ctrl+h for KB shortcuts

NumPy

Sort array by nth column in Numpy/Python

# sort array with regards to nth column
arr = arr[arr[:,n].argsort()]
https://snipt.net/embed/40d7e32447ad183bf59483a74b6a6fbb/
/raw/40d7e32447ad183bf59483a74b6a6fbb/
40d7e32447ad183bf59483a74b6a6fbb
numpy
NumPy
2
2019-08-21T21:04:01
True
False
False
/api/public/snipt/51255/
sort-array-by-nth-column-in-numpypython
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1"># sort array with regards to nth column</span> </span><span id="L-2"><a name="L-2"></a><span class="n">arr</span> <span class="o">=</span> <span class="n">arr</span><span class="p">[</span><span class="n">arr</span><span class="p">[:,</span><span class="n">n</span><span class="p">]</span><span class="o">.</span><span class="kp">argsort</span><span class="p">()]</span> </span></pre></div> </td></tr></table>
Python, array, numpy, sort