这是一个完美的案例,其中
scipy.spatial.cKDTree()该类可用于一次查询所有点:
from scipy.spatial import cKDTreek = cKDTree(data[:, 6:8]) # creating the KDtree using the Xpos and YposxyCenters = np.array([[200.6, 310.9],[300, 300],[400, 400]])print(k.query(xyCenters))# (array([ 1.59740195, 1.56033234, 0.56352196]),# array([ 2662, 22789, 5932]))
其中
[ 2662, 22789,5932]的索引对应于中给出的三个最接近的点
xyCenters。您可以使用以下索引来高效地获取您的
ra和
dec值
np.take():
dists, indices = k.query(xyCenters)myra = np.take(ra, indices)mydec = np.take(dec, indices)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)