local maxima prototype

This commit is contained in:
ASPP Student 2025-09-23 16:22:34 +03:00
parent 952f8b97a5
commit 47f74329bf
2 changed files with 18 additions and 2 deletions

View file

@ -7,9 +7,18 @@ def find_maxima(x):
Output:
idx -- list of indices of the local maxima in x
"""
return []
idx = []
for i in range(len(x)):
if i == 0 and x[i] > x[i+1]:
idx.append(i)
elif i != len(x)-1 and x[i] > x[i-1] and x[i] > x[i+1]:
idx.append(i)
elif i== len(x)-1 and x[i] > x[i-1]:
idx.append(i)
return idx
if __name__ == "__main__":
x = [1, 2, 3]
# x = [1,2,2,3,1]
print(find_maxima(x))