我有一个一维numpy数组(arr0),有不同的值。 我想创建一个新的元素数组,其中每个元素都是一个元素与其最接近的元素的一对(索引和/或值),考虑到成对元素的差异(距离)的绝对值低于设置的阈值。在
在每一步(耦合)我想删除已经耦合的元素。在
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]]
您可以想象这样的情况,使用
sklearn.metrics.pairwise_distances
计算所有成对距离:在您的例子中,它会产生:
^{pr2}$相关问题 更多 >
编程相关推荐