<div dir="ltr">With the new np.partition functionality, there is a more efficient, but also less obvious, way of extracting the n largest (or smallest) elements from an array, i.e.:<div><br></div><div><div>def smallest_n(a, n):</div>
<div>    return np.sort(np.partition(a, n)[:n])</div><div><br></div><div>def argsmallest_n(a, n):</div><div>    ret = np.argpartition(a, n)[:n]</div><div>    b = np.take(a, ret)</div><div>    return np.take(ret, np.argsort(b))</div>
</div><div><br></div><div>instead of the usual:</div><div><br></div><div>np.sort(a)[:n]</div><div>np.argsort(a)[:n]</div><div><br></div><div>Are those 4 functions (smallest, argsmallest, largest, arglargest), with adequate axis support, worthy of including in numpy, or is the name space already too cluttered?</div>
<div><br></div><div>Jaime</div><div><br clear="all"><div>-- <br></div>(\__/)<br>( O.o)<br>( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes de dominación mundial.
</div></div>