n_samples is the number of points in the data set, and
n_features is the dimension of the parameter space.
Note: if X is a C-contiguous array of doubles then data will
not be copied. Otherwise, an internal copy will be made.

leaf_size:positive integer (default = 40)

Number of points at which to switch to brute-force. Changing
leaf_size will not affect the results of a query, but can
significantly impact the speed of a query and the memory required
to store the constructed tree. The amount of memory needed to
store the tree scales as approximately n_samples / leaf_size.
For a specified leaf_size, a leaf node is guaranteed to
satisfy leaf_size<=n_points<=2*leaf_size, except in
the case that n_samples<leaf_size.

metric:string or DistanceMetric object

the distance metric to use for the tree. Default=’minkowski’
with p=2 (that is, a euclidean metric). See the documentation
of the DistanceMetric class for a list of available metrics.
kd_tree.valid_metrics gives a list of the metrics which
are valid for KDTree.

Specify the desired relative and absolute tolerance of the result.
If the true result is K_true, then the returned result K_ret
satisfies abs(K_true-K_ret)<atol+rtol*K_ret
The default is zero (i.e. machine precision) for both.

breadth_first:boolean (default = False)

if True, use a breadth-first search. If False (default) use a
depth-first search. Breadth-first is generally faster for
compact kernels and/or high tolerances.

return_log:boolean (default = False)

return the logarithm of the result. This can be more accurate
than returning the result itself for narrow kernels.

if True, return a tuple (d, i) of distances and indices
if False, return array i

dualtree:boolean (default = False)

if True, use the dual tree formalism for the query: a tree is
built for the query points, and the pair of trees is used to
efficiently search this space. This can lead to better
performance as the number of points grows large.

breadth_first:boolean (default = False)

if True, then query the nodes in a breadth-first manner.
Otherwise, query the nodes in a depth-first manner.

sort_results:boolean (default = True)

if True, then distances and indices of each point are sorted
on return, so that the first column contains the closest points.
Otherwise, neighbors are returned in an arbitrary order.

Returns:

i:if return_distance == False

(d,i):if return_distance == True

d:array of doubles - shape: x.shape[:-1] + (k,)

each entry gives the list of distances to the
neighbors of the corresponding point

i:array of integers - shape: x.shape[:-1] + (k,)

each entry gives the list of indices of
neighbors of the corresponding point

r can be a single value, or an array of values of shape
x.shape[:-1] if different radii are desired for each point.

return_distance:boolean (default = False)

if True, return distances to neighbors of each point
if False, return only neighbors
Note that unlike the query() method, setting return_distance=True
here adds to the computation time. Not all distances need to be
calculated explicitly for return_distance=False. Results are
not sorted by default: see sort_results keyword.

count_only:boolean (default = False)

if True, return only the count of points within distance r
if False, return the indices of all points within distance r
If return_distance==True, setting count_only=True will
result in an error.

sort_results:boolean (default = False)

if True, the distances and indices will be sorted before being
returned. If False, the results will not be sorted. If
return_distance == False, setting sort_results = True will
result in an error.

Returns:

count:if count_only == True

ind:if count_only == False and return_distance == False

(ind, dist):if count_only == False and return_distance == True

count:array of integers, shape = X.shape[:-1]

each entry gives the number of neighbors within
a distance r of the corresponding point.

ind:array of objects, shape = X.shape[:-1]

each element is a numpy integer array listing the indices of
neighbors of the corresponding point. Note that unlike
the results of a k-neighbors query, the returned neighbors
are not sorted by distance by default.

dist:array of objects, shape = X.shape[:-1]

each element is a numpy double array
listing the distances corresponding to indices in i.