def find_maxima(x): """Find local maxima of x. Input arguments: x -- 1D list of real numbers Output: idx -- list of indices of the local maxima in x """ idx = [] for i in range(1, len(x)-1): if (x[i] > x[i-1]) & (x[i] > x[i+1]): idx.append(i) return idx if __name__ == "__main__": x = [1, 3, -2, 0, 2, 1] print(find_maxima(x))