-1
from scipy.signal import find_peaks
a=[2,3,4,1]
b=find_peaks(a)
print(b)

I am getting the indices. But I want the values. How can I get the values of the list?

buran
  • 13,682
  • 10
  • 36
  • 61

2 Answers2

0

You can use the indices on the original vector to return the value of the peak like this:

a = np.array([2, 3, 4, 1])
peaks, properties = find_peaks(a)
a[peaks]
ethanknights
  • 154
  • 5
0

The easiest way is to convert a to a numpy array then index it.

a = np.array([2, 3, 4, 1, 5, 0], dtype=np.float32)
idx, props = find_peaks(a)
val = a[idx]

print(idx)  # this outputs [2 4]
print(val)  # this outputs [4. 5.]
brentertainer
  • 2,118
  • 1
  • 6
  • 15