【发布时间】:2022-01-13 22:40:51
【问题描述】:
我正在使用 KDTree 结构进行球形邻居研究。我使用sklearn.neigbors.KDTree中的query_radius方法
在文档here 上,它说索引作为“对象”类型返回。究竟是什么意思?我可以将它们转换为整数吗?为什么query 方法不是这样(索引以整数形式返回)?
这是我的代码的重要部分:
import numpy as np
from sklearn.neighbors import KDTree
def kdtree_spherical(queries, supports, radius, leaf_size=40):
supports_tree = KDTree(supports, leaf_size=leaf_size)
ind = supports_tree.query_radius(queries, r=radius, return_distance=False)
return supports[ind]
# Define the search parameters
points = ... # array of size N*3, N is very big basically
neighbors_num = 100
radius = 0.2
num_queries = 1000
random_indices = np.random.choice(points.shape[0], num_queries, replace=False)
queries = points[random_indices, :]
# Search spherical
neighborhoods = kdtree_spherical(queries, points, radius)
出现以下错误
Traceback (most recent call last):
File "neighborhoods.py", line 178, in <module>
neighborhoods = kdtree_spherical(queries, points, radius, leaf_size)
File "neighborhoods.py", line 79, in kdtree_spherical
return supports[ind]
IndexError: arrays used as indices must be of integer (or boolean) type
【问题讨论】:
标签: python scikit-learn kdtree