Add simple local maxima function #6

Open
eceku wants to merge 1 commit from eceku/2025-plovdiv-testing-debugging:fix-1 into main
Showing only changes of commit 5270dc288f - Show all commits

View file

@ -1,4 +1,4 @@
def find_maxima(x):
def find_maxima(input_list):
"""Find local maxima of x.
Input arguments:
@ -7,4 +7,16 @@ def find_maxima(x):
Output:
idx -- list of indices of the local maxima in x
"""
return []
local_maxima = []
for i, val in enumerate(input_list):
if i == 0 or i == len(input_list)-1:
continue
if input_list[i-1] < val and input_list[i+1] < val:
local_maxima.append(i)
if len(input_list) > 0:
if input_list[0] > input_list[1]:
local_maxima.append(0)
if input_list[-1] > input_list[-2]:
local_maxima.append(len(input_list)-1)
return sorted(local_maxima)