scipy.spatial.cKDTree.query_ball_point¶
-
cKDTree.
query_ball_point
(self, x, r, p=2., eps=0)¶ Find all points within distance r of point(s) x.
- Parameters
- xarray_like, shape tuple + (self.m,)
The point or points to search for neighbors of.
- rpositive float
The radius of points to return.
- pfloat, optional
Which Minkowski p-norm to use. Should be in the range [1, inf].
- epsnonnegative float, optional
Approximate search. Branches of the tree are not explored if their nearest points are further than
r / (1 + eps)
, and branches are added in bulk if their furthest points are nearer thanr * (1 + eps)
.- n_jobsint, optional
Number of jobs to schedule for parallel processing. If -1 is given all processors are used. Default: 1.
- return_sortedbool, optional
Sorts returned indicies if True and does not sort them if False. If None, does not sort single point queries, but does sort multi-point queries which was the behavior before this option was added.
New in version 1.2.0.
- Returns
- resultslist or array of lists
If x is a single point, returns a list of the indices of the neighbors of x. If x is an array of points, returns an object array of shape tuple containing lists of neighbors.
Notes
If you have many points whose neighbors you want to find, you may save substantial amounts of time by putting them in a cKDTree and using query_ball_tree.
Examples
>>> from scipy import spatial >>> x, y = np.mgrid[0:4, 0:4] >>> points = np.c_[x.ravel(), y.ravel()] >>> tree = spatial.cKDTree(points) >>> tree.query_ball_point([2, 0], 1) [4, 8, 9, 12]