I have 1-dimensional numpy array (arr0) with different values. I want to create a new array of elements, where each element is a couple (indexes and/or values) of one element to its closest one, considering that the absolute value of the difference (distance) of the couple is lower than a set threshold.
At each step (coupling) I would like to remove the elements already coupled.
arr0 = [40, 55, 190, 80, 175, 187] #My original 1D array
threshold = 20 #Returns elements if "abs(el_1 - el_2)<threshold"
#For each couple found, the code should remove the couple from the array and then go on with the next couple
result_indexes = [[0, 1], [2, 5]]
result_value = [[40, 55], [190, 187]]