fixed find maxima function first 3
This commit is contained in:
parent
952f8b97a5
commit
d03243efe4
2 changed files with 29 additions and 1 deletions
|
@ -7,4 +7,22 @@ def find_maxima(x):
|
|||
Output:
|
||||
idx -- list of indices of the local maxima in x
|
||||
"""
|
||||
return []
|
||||
localmax = []
|
||||
|
||||
for i, num in enumerate(x):
|
||||
if i == 0:
|
||||
if x[i+1] < x[i]:
|
||||
localmax.append(i)
|
||||
elif i == len(x)-1:
|
||||
if x[i-1] < x[i]:
|
||||
localmax.append(i)
|
||||
else:
|
||||
if x[i+1] < x[i] and x[i-1] < x[i]:
|
||||
localmax.append(i)
|
||||
|
||||
return localmax
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
x = [1, 2, 3]
|
||||
print(find_maxima(x))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue