【问题标题】:KDTree double type integersKDTree 双精度型整数
【发布时间】:2017-01-06 01:59:32
【问题描述】:

我有一个二维坐标列表,我正在从中创建kdtree。坐标类型为double- 例如[508180.748, 195333.973]

我使用 numpy 创建数组,然后使用 scipy 的 KDTree 函数。

import numpy as np
import scipy.spatial

points_array = np.array(points)
kdt = scipy.spatial.KDTree(points_array)

# Query    
tester = kdt.query_pairs(20)
tester = list(tester)    
print(tester[0])

这会返回:

(109139, 109144)

结果丢失了原始数据的分辨率。如何保持双精度浮点格式?

【问题讨论】:

    标签: python numpy scipy kdtree


    【解决方案1】:

    这些是点数组中的索引,而不是点本身的坐标值。元组有两个索引,一个用于数组中的每个点,该点是一对在您的坐标空间中的间隔小于查询距离的部分。

    要查看对中点的坐标值,您可以执行以下操作:

    tester = kdt.query_pairs(20)
    tester = list(tester)    
    print(points_array[tester[0][0]], points_array[tester[0][1]])
    

    【讨论】:

    • 谢谢!我试过了,它返回了(array([ 527948., 169578.]), array([ 527959., 169593.])) 为什么它会丢弃任何超过. 的东西?
    • 我在使用此代码时获得了完整的精度,所以恐怕我不知道您为什么会看到这种行为。我的猜测是这些值在. 之后没有任何内容,或者您​​还有其他问题,可能与dtype 有关。您必须发布回溯,以便有人帮助您进行故障排除。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-20
    • 2016-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-13
    相关资源
    最近更新 更多