This might be a simple problem but I haven't come up with a solution.
Say I have an array as np.array([0,1,0,1,0,0,0,1,0,1,0,0,1])
with peaks at indexes [1,3,7,9,12]
. How can I replace the indexes with [2,8,12]
, that is, averaging indexes close in distance, if a threshold distance between peaks is set to be greater than 2
in this example?
Please note that the binary values of the array are just for illustration, the peak value can be any real number.