find local maxima

This commit is contained in:
ASPP Student 2025-09-23 15:21:50 +03:00
parent 952f8b97a5
commit 8ae15bf2a5

View file

@ -7,9 +7,13 @@ def find_maxima(x):
Output: Output:
idx -- list of indices of the local maxima in x idx -- list of indices of the local maxima in x
""" """
return [] 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__": if __name__ == "__main__":
x = [1, 2, 3] x = [1, 3, -2, 0, 2, 1]
print(find_maxima(x)) print(find_maxima(x))