Given a list, your job is to find values which are surrounded by greater values on both sides. such values are called local minima. for example, the number '1' (present at index 1) is a local minimum in the given series: [2,1,2]
Note: Do not consider the first and last element of the list as local minima. A point is local minima if the two elements surrounding it are greater than the number. For example, there is not minim in this list: [1,2,2,2,1].
Input format: The input will be a list of numbers.
Output Format: The output should be a list of indices of the local minima stored in increasing order.
Hint: You can convert it into a numpy/pandas series to use the inbuilt functions from pandas and numpy.
Sample Input: [2,1,3,4,1,5,6,1,7]
Sample Output: [1, 4, 7]
Note: There are multiple ways to do this. Try to choose a method other than using simple loops and comparisons.
Find Local Minima Python
import ast,sys
import numpy as np
input_str = sys.stdin.read()
input_list = ast.literal_eval(input_str)
l=np.array(input_list)
from scipy.signal import argrelextrema
minimas=list(argrelextrema(l, np.less)[0]) #store your final list here
minimas=[int(x) for x in minimas] #do not change this code, the output should be an integer list for evaluation purposes
print(minimas)
Comments