带有元数据的scipy kdtree [英] scipy kdtree with meta data

查看:81
本文介绍了带有元数据的scipy kdtree的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在寻找一种方法来构建几棵kd树,以便快速查询某些n维数据.但是,scipy KD树算法存在一些问题

I'm currently looking for a way to build a couple of kd trees for quickly querying some n-dimensional data. However, I'm having some issue with the scipy KD tree algorithm

我的数据由 id->组成.{数据:一些数据,坐标:x,y}

我希望能够基于坐标和k近邻的ID进行查询,并获取固定半径的邻居的ID.从KDTree和cKDtree的科学实现来看,这是不可用的.

I want to be able to query base on the coordinate and k-nearest neighbour's ids as well as getting the fix radius neghbour's id. Judging from the scipy implementation of KDTree and cKDtree, this is not available.

我的其他选择是编写我自己的KD树,因为我只是我,否则...不会那么好.

My other options are writing my own KD tree, which will not be that great because I'm just me, or ...?

推荐答案

从玩弄

From playing around with the KDTree, it looks like it insists on having a 2D numpy array like object given to its constructor, but the API returns indices into that array. Further, you can't just monkey patch your data onto the individual coordinates.

但是,您仍然可以利用KDTree的勇气.您需要将对象拆分为附加数据对象的并行列表,以及KDTree看到的坐标的numpy数组.当它说出来时,返回第三个点进行搜索,您知道该点对应于附加数据对象列表中的第三个索引.

But, you can still take advantage of the guts of the KDTree. You need to split your object into a parallel list of the attached data objects, and a numpy array of the coordinates that the KDTree sees. When it say, returns the 3rd point for some search, you know that corresponds to the 3rd index in your attached data object list.

当然,它比提供给您一个键函数来提供任意对象的坐标的API笨拙,类似于如何将键传递给python sort函数,但这比滚动自己的KDTree实现好得多.

Sure, it's more awkward than an API that would give you a key function that gives coordinates from an arbitrary object, akin to how you can pass key to the python sort function, but it's much better than rolling your own KDTree implementation.

这篇关于带有元数据的scipy kdtree的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆