I have an array of values
array = [100, 101, 102, 102.001, 103.2, 104.64, 106.368, 108.442]
Values 102
and 102.001
should be the same. I'd like to find the most best way to remove the value 102.001
and not 102
.
So far I have a cumbersome method to do this, but this would remove 102
if the array was reversed;
import numpy as np
array = [100, 101, 102, 102.001, 103.2, 104.64, 106.368, 108.442]
array_diff = np.ediff1d(array)
ai = np.array(np.where(array_diff<0.01))
array_out = np.delete(array,[ai[0][0]+1])
Is there a way to merge/remove values given a tolerance?
Thanks in advance.