find local maxima
This commit is contained in:
parent
952f8b97a5
commit
8ae15bf2a5
1 changed files with 6 additions and 2 deletions
|
@ -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))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue