def filter_n_largest(y, cands, N):
    cands = np.asarray(cands)
    N = int(N)
    if N <= 0:
        raise ValueError("The maximum number of peaks to return must "
                         "be positive not {}".format(N))

    sorted_args = np.argsort(y[cands])
    # cut out if asking for more peaks than exist
    if len(cands) < N:
        return cands[sorted_args][::-1]

    return cands[sorted_args[-N:]][::-1]
Filters the N largest candidate peaks
dataset/ETHPy150Open scikit-beam/scikit-beam/skbeam/core/feature.py/filter_n_largest