python - 如何在知道索引的同时减少到没有任何远距离元素对的数组
问题描述
例如我有:
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 中有建议,我会接受。
解决方案
推荐阅读
- selenium - Selenium:ChromeDriver 和 Chromium-Browser 和 Raspberry Pi 之间的不同版本
- java - Java 访问对象中的数组
- python - Python中的惰性排序
- javascript - 如何根据按钮单击验证表单字段?
- javascript - 我需要在我的反应组件中为 text2 创建一个延迟
- c - 无法在共享对象文件中通过 system() 命令运行 python 文件
- android - 如何增强和提高 recyclerView 适配器的性能
- spring - Spring Security WebTestClient 在模拟 JWT 时不调用 OncePerRequestFilter
- ab-testing - 如果我将更改推送到着陆页,Google 优化工具会继续测试我的页面变体吗?
- java - 通用消息如何
作品?