是否有一种Scipy(或类似的Python库)方法来在矩形中查询KDTREE而不是圆圈?

发布于 2025-02-12 03:07:23 字数 1384 浏览 0 评论 0原文

我在数组中有2D点的列表,Shape [M,2]其中m非常非常大。我需要创建小“盒子”,shape [n,n],其中n很奇怪,以便数组的中心元素是我感兴趣的观点,数组的其他元素是k = n*n*n-1最近的邻居。使用Scipy,从第一个数组中构建一个KDTREE,然后抓住最接近的邻居到我对某个距离感兴趣的观点,这是一个相当简单的努力,但是可悲的是,这些点会构造一个点圈,而我需要一个盒子。

我将展示一个简单的例子,说明这是有道理的。我要n = 3,我会查询点[1,2]

array = [[0,0], --> tree = createtree(array) --> tree.query_box([1,2], [3,3]) = [[0,1],
         [0,1],                                                                  [0,2],
         [0,2],                                                                  [0,3],
         [0,3],                                                                  [1,1],
         [1,0],                                                                  [1,2],
         [1,1],                                                                  [1,3],
         [1,2],                                                                  [2,1],
         [1,3],                                                                  [2,2],
         [2,0],                                                                  [2,3]]
         [2,1],
         [2,2],
         [2,3],
         [3,0],
         [3,1],
         [3,2],
         [3,3]]

我可以找到的最接近的东西是tree.query_ball_point([1,2 ],r = 3),但是正如我所说,这些点会创建一个圆圈而不是盒子。

I have a list of 2d points in an array, shape [m, 2] where m is very, very large. I need to create small "boxes", shape [n, n], where n is odd so that the center element of the array is the point I am interested in, and the other elements of the array are the k = n*n-1 nearest neighbors around that point of interest. Using SciPy, it is a fairly simple endeavor to construct a KDTree from the first array and then grab the closest neighbors to the point I'm interested in withing a certain distance, but sadly those points will construct a circle of points, whereas I need a box.

I'll show a simple example of what I want just so it hopefully makes sense. I'll want n=3 and I will query the point [1,2]

array = [[0,0], --> tree = createtree(array) --> tree.query_box([1,2], [3,3]) = [[0,1],
         [0,1],                                                                  [0,2],
         [0,2],                                                                  [0,3],
         [0,3],                                                                  [1,1],
         [1,0],                                                                  [1,2],
         [1,1],                                                                  [1,3],
         [1,2],                                                                  [2,1],
         [1,3],                                                                  [2,2],
         [2,0],                                                                  [2,3]]
         [2,1],
         [2,2],
         [2,3],
         [3,0],
         [3,1],
         [3,2],
         [3,3]]

The closest thing I can find is tree.query_ball_point([1,2],r=3), but as I said, those points create a circle not a box.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文