異なる値を持つ 1 次元の numpy 配列 (arr0) があります。ペアの差 (距離) の絶対値がセットよりも小さいことを考慮して、各要素が最も近い要素への 1 つの要素のカップル (インデックスおよび/または値) である要素の新しい配列を作成したいしきい値。
各ステップ (結合) で、既に結合されている要素を削除したいと思います。
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]]