首页 > 解决方案 > 如何在知道索引的同时减少到没有任何远距离元素对的数组

问题描述

例如我有:

x = array([[0.       , 0.94],
           [0.9486833, 0.94],
           [1.8973666, 0.94],
           [2.8460498, 0.94],
           [0.9486833, 0.94]], dtype=float32)

y = array([   [1],
              [2],
              [3],
              [4],
              [5]], dtype=float32)

并且由于在 x 中有两个元素彼此相距很远,因此我只想根据 x 中彼此相近某个阈值的元素保留一个,然后删除一个,我的结果是:

x = array([[0.       , 0.94],

           [1.8973666, 0.94],
           [2.8460498, 0.94],
           [0.9486833, 0.94]], dtype=float32)

y = array([   [1],

              [3],
              [4],
              [5] ], dtype=float32)

因此,如果我知道 x 中的哪些索引是我保留或删除的,那么我也可以构造正确对应于 x 的其余元素的 y。

另外我已经从 tensorflow 转换为 numpy 数组,如果 tensorflow 中有建议,我会接受。

标签: pythonnumpytensorflowscipy

解决方案


推荐阅读