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