本文簡要介紹 python 語言中 scipy.spatial.KDTree.query_ball_point
的用法。
用法:
KDTree.query_ball_point(x, r, p=2.0, eps=0, workers=1, return_sorted=None, return_length=False)#
找到點 x 的距離 r 內的所有點。
- x: 數組, 形狀元組 + (self.m,)
要搜索其鄰居的一個或多個點。
- r: 數組,浮點數
要返回的點的半徑,必須廣播到 x 的長度。
- p: 浮點數,可選
使用哪個 Minkowski p-norm。應在 [1, inf] 範圍內。如果可能發生溢出,有限的大 p 可能會導致 ValueError。
- eps: 非負浮點數,可選
近似搜索。如果樹的最近點比
r / (1 + eps)
更遠,則不探索樹的分支,如果最遠點比r * (1 + eps)
更近,則批量添加分支。- workers: 整數,可選
要為並行處理安排的作業數。如果給定 -1,則使用所有處理器。默認值:1。
- return_sorted: 布爾型,可選
如果為 True,則對返回的索引進行排序,如果為 False,則不對它們進行排序。如果為 None,則不對單點查詢進行排序,而是對 multi-point 查詢進行排序,這是添加此選項之前的行為。
- return_length: 布爾型,可選
返回半徑內的點數,而不是索引列表。
- results: 列表或列表數組
如果 x 是單點,則返回 x 的鄰居的索引列表。如果 x 是點數組,則返回包含鄰居列表的形狀元組的對象數組。
參數 ::
返回 ::
注意:
如果您有許多要查找其鄰居的點,則可以通過將它們放入 KDTree 並使用 query_ball_tree 來節省大量時間。
例子:
>>> import numpy as np >>> from scipy import spatial >>> x, y = np.mgrid[0:5, 0:5] >>> points = np.c_[x.ravel(), y.ravel()] >>> tree = spatial.KDTree(points) >>> sorted(tree.query_ball_point([2, 0], 1)) [5, 10, 11, 15]
查詢多個點並繪製結果:
>>> import matplotlib.pyplot as plt >>> points = np.asarray(points) >>> plt.plot(points[:,0], points[:,1], '.') >>> for results in tree.query_ball_point(([2, 0], [3, 3]), 1): ... nearby_points = points[results] ... plt.plot(nearby_points[:,0], nearby_points[:,1], 'o') >>> plt.margins(0.1, 0.1) >>> plt.show()
相關用法
- Python SciPy KDTree.query_ball_tree用法及代碼示例
- Python SciPy KDTree.query_pairs用法及代碼示例
- Python SciPy KDTree.query用法及代碼示例
- Python SciPy KDTree.sparse_distance_matrix用法及代碼示例
- Python SciPy KDTree.count_neighbors用法及代碼示例
- Python SciPy KroghInterpolator.derivatives用法及代碼示例
- Python SciPy interpolate.make_interp_spline用法及代碼示例
- Python SciPy stats.anderson用法及代碼示例
- Python SciPy ClusterNode.pre_order用法及代碼示例
- Python SciPy stats.iqr用法及代碼示例
- Python SciPy FortranFile.read_record用法及代碼示例
- Python SciPy ndimage.correlate用法及代碼示例
- Python SciPy special.exp1用法及代碼示例
- Python SciPy special.expn用法及代碼示例
- Python SciPy signal.czt_points用法及代碼示例
- Python SciPy interpolate.krogh_interpolate用法及代碼示例
- Python SciPy ndimage.morphological_gradient用法及代碼示例
- Python SciPy distance.sokalmichener用法及代碼示例
- Python SciPy linalg.eigvalsh_tridiagonal用法及代碼示例
- Python SciPy linalg.cdf2rdf用法及代碼示例
- Python SciPy csc_array.diagonal用法及代碼示例
- Python SciPy fft.idctn用法及代碼示例
- Python SciPy linalg.LaplacianNd用法及代碼示例
- Python SciPy linalg.solve_circulant用法及代碼示例
- Python SciPy hierarchy.ward用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.spatial.KDTree.query_ball_point。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。