13 Dec
2013
13 Dec
'13
2:07 a.m.
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.: def smallest_n(a, n): return np.sort(np.partition(a, n)[:n]) def argsmallest_n(a, n): ret = np.argpartition(a, n)[:n] b = np.take(a, ret) return np.take(ret, np.argsort(b)) instead of the usual: np.sort(a)[:n] np.argsort(a)[:n] 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? Jaime -- (\__/) ( O.o) ( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes de dominación mundial.