def find_sorted_peaks(x):
    """Find peaks, i.e. local maxima, of an array. Interior points are peaks if
    they are greater than both their neighbors, and edge points are peaks if
    they are greater than their only neighbor. In the case of ties, we
    (arbitrarily) choose the first index in the sequence of equal values as the
    peak.

    Returns a list of tuples (i, x[i]) of peak indices i and values x[i],
    sorted in decreasing order by peak value.
     """
    peak_inds = []
    nbins = len(x)
    for i in range(nbins):
        if i == 0 or x[i-1] > x[i]: # Increasing from left
            if i == nbins-1 or x[i] > x[i+1]: # Increasing from right
                peak_inds.append(i)
            elif x[i] == x[i+1]: # Tied; check the next non-equal value
                for j in range(i+1, nbins):
                    if x[j] != x[i]:
                        if x[j] < x[i]:
                            peak_inds.append(i)
                        break
                if j == nbins-1 and x[i] == x[j]: # Reached the end
                    peak_inds.append(i)
    sorted_peak_inds = sorted(peak_inds, key=lambda i: x[i], reverse=True)
    return list(zip(sorted_peak_inds, x[sorted_peak_inds]))
dataset/ETHPy150Open cesium-ml/cesium/cesium/obs_feature_tools.py/find_sorted_peaks/swapped operands of `>`