bundles / scipy 1.17.1 / scipy / spatial / _ckdtree / cKDTree
class
scipy.spatial._ckdtree:cKDTree
source: /scipy/spatial/_ckdtree.cpython-314-x86_64-linux-gnu.so
Signature
class cKDTree ( data , leafsize = 16 , compact_nodes = True , copy_data = False , balanced_tree = True , boxsize = None ) Members
-
__getstate__ -
__reduce_cython__ -
__setstate__ -
__setstate_cython__ -
_build_weights -
count_neighbors -
query -
query_ball_point -
query_ball_tree -
query_pairs -
sparse_distance_matrix
Summary
kd-tree for quick nearest-neighbor lookup
Extended Summary
This class provides an index into a set of k-dimensional points which can be used to rapidly look up the nearest neighbors of any point.
Parameters
data: array_like, shape (n,m)The n data points of dimension m to be indexed. This array is not copied unless this is necessary to produce a contiguous array of doubles, and so modifying this data will result in bogus results. The data are also copied if the kd-tree is built with copy_data=True.
leafsize: positive int, optionalThe number of points at which the algorithm switches over to brute-force. Default: 16.
compact_nodes: bool, optionalIf True, the kd-tree is built to shrink the hyperrectangles to the actual data range. This usually gives a more compact tree that is robust against degenerated input data and gives faster queries at the expense of longer build time. Default: True.
copy_data: bool, optionalIf True the data is always copied to protect the kd-tree against data corruption. Default: False.
balanced_tree: bool, optionalIf True, the median is used to split the hyperrectangles instead of the midpoint. This usually gives a more compact tree and faster queries at the expense of longer build time. Default: True.
boxsize: array_like or scalar, optionalApply an m-d toroidal topology to the KDTree. The topology is generated by where are integers and is the boxsize along i-th dimension. The input data shall be wrapped into . A ValueError is raised if any of the data is outside of this bound.
Attributes
data: ndarray, shape (n,m)The n data points of dimension m to be indexed. This array is not copied unless this is necessary to produce a contiguous array of doubles. The data are also copied if the kd-tree is built with
copy_data=True.leafsize: positive intThe number of points at which the algorithm switches over to brute-force.
m: intThe dimension of a single data-point.
n: intThe number of data points.
maxes: ndarray, shape (m,)The maximum value in each dimension of the n data points.
mins: ndarray, shape (m,)The minimum value in each dimension of the n data points.
tree: object, class cKDTreeNodeThis attribute exposes a Python view of the root node in the cKDTree object. A full Python view of the kd-tree is created dynamically on the first access. This attribute allows you to create your own query functions in Python.
size: intThe number of nodes in the tree.
Notes
The algorithm used is described in [1]. The general idea is that the kd-tree is a binary tree, each of whose nodes represents an axis-aligned hyperrectangle. Each node specifies an axis and splits the set of points based on whether their coordinate along that axis is greater than or less than a particular value.
During construction, the axis and splitting point are chosen by the "sliding midpoint" rule, which ensures that the cells do not all become long and thin.
The tree can be queried for the r closest neighbors of any given point (optionally returning only those within some maximum distance of the point). It can also be queried, with a substantial gain in efficiency, for the r approximate closest neighbors.
For large dimensions (20 is already large) do not expect this to run significantly faster than brute force. High-dimensional nearest-neighbor queries are a substantial open problem in computer science.
Aliases
-
scipy.spatial.cKDTree