How to convert scipy find_peaks values result to list? I want to sort the amplitude values.
p = find_peaks(data,height=60,distance=3)
p_ind,p_val = p
a=list(p_val.values())
a.sort(reverse=True)
The problem here is the command is executing without any error, but sorting does not take place because 'a' is a list containing only one element which is an array. I want to sort that array and address it like a[1], a[2], etc,.
The value of a is
[array([76., 66., 60., 61., 63., 82., 67., 72., 69., 65., 71., 77., 66., 80., 67., 73., 65., 75., 76., 72., 68., 71., 76., 74., 73., 71., 71., 71., 71., 78., 66., 80., 63., 64., 74., 69., 68., 66., 73., 66., 77., 74., 74., 67., 64., 72., 69., 69., 62., 72., 63., 68., 69., 69., 65., 66., 63., 64., 61., 67.])]
I know it sounds like a simple doubt, but I am unable to find it out. Any help would be appreciated.
CodePudding user response:
a=[array('d',[76., 66., 60., 61., 63., 82., 67., 72., 69.])]
print(a)
a=list(a[0])
a.sort(reverse=True)
print(a)
You can take the element at 0 position index (array in list). This is an iterable and you can assign again to 'a' variable. Now 'a' is a list and you can call sort method with reverse parameter.
CodePudding user response:
For height, the first element is considered as the minimum value therefore give range accordingly. And while extracting peak_heights, peak_val is a dictionary so select 'peak_heights' from it.
peak_ind, peak_val = find_peaks(data, height = [0,60], distance = 3)
a = list(peak_val['peak_heights'])
b = sorted(a)
print(b)
[0.005, 0.015, 0.02, 0.025, 0.03, 0.03, 0.045, 0.05, 0.055, 0.055, 0.065, 0.065, 0.07, 0.09, 0.105, 0.105, 0.135, 0.16, 0.165, 0.2, 0.205, 0.21, 0.23, 0.235, 0.24, 0.245, 0.245, 0.26, 0.265, 0.265, 0.28, 0.29, 0.3, 0.31, 0.31, 0.32, 0.32, 0.33, 0.335, 0.335, 0.35, 0.36, 0.36, 0.36, 0.36, 0.36, 0.365, 0.365, 0.375, 0.39, 0.395, 0.4, 0.42, 0.43, 0.435, 0.44, 0.44, 0.445, 0.445, 0.445, 0.45, 0.455, 0.46, 0.465, 0.465, 0.47, 0.48, 0.495, 0.505, 0.51, 0.515, 0.525, 0.535, 0.535, 0.54, 0.54, 0.545, 0.55, 0.55, 0.55, 0.55, 0.555, 0.56, 0.56, 0.56, 0.565, 0.57, 0.585, 0.585, 0.59, 0.59, 0.595, 0.6, 0.605, 0.625, 0.625, 0.625, 0.63, 0.635, 0.655, 0.66, 0.665, 0.665, 0.7, 0.705, 0.705, 0.705, 0.71, 0.71, 0.71, 0.72, 0.72, 0.75, 0.76, 0.77, 0.775, 0.78, 0.81, 0.83, 0.84, 0.88, 0.9, 0.92, 0.935, 0.95, 0.955, 1.155, 1.2, 1.37, 1.705, 1.745, 1.925, 1.96, 2.09]