def argsort_k_smallest ( x , k ) : if k == 0 : return np . array ( [ ] , dtype = np . intp ) if k is None or k >= len ( x ) : return np . argsort ( x ) indices = np . argpartition ( x , k ) [ : k ] values = x [ indices ] return indices [ np . argsort ( values ) ]
indices of k smallest elements python
Return no more than k indices of smallest values .
def argsort_k_smallest(x, k):
    """ Return no more than ``k`` indices of smallest values. """
    if k == 0:
        return np.array([], dtype=np.intp)
    if k is None or k >= len(x):
        return np.argsort(x)
    indices = np.argpartition(x, k)[:k]
    values = x[indices]
    return indices[np.argsort(values)]