是否有一种Scipy(或类似的Python库)方法来在矩形中查询KDTREE而不是圆圈?
我在数组中有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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论