20 lines
489 B
Python
20 lines
489 B
Python
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
|
|
"""
|
|
sol = []
|
|
for idx, num in enumerate(x):
|
|
if idx == 0 and num => x[idx+1]:
|
|
sol.append(idx)
|
|
elif idx == len(x)-1 and num => x[idx-1]:
|
|
sol.append(idx)
|
|
else:
|
|
if x[idx-1] <= num and num => x[idx+1]:
|
|
sol.append(idx)
|
|
|
|
return sol
|