Initial version of local_maxima
This commit is contained in:
parent
952f8b97a5
commit
7c2448f2da
1 changed files with 11 additions and 1 deletions
|
@ -7,4 +7,14 @@ 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 []
|
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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue