Search code examples
pythonscipyspatialkdtree

What unit does scipy's kdtree function return distance in?


I'm new to KD trees and I'm using them to find the nearest neighbour for each point in one array (search_array), compared with all the points in a second array (vec_array).

Both arrays are formatted like so:

array([[ 51.54094696,   0.09767043],
   [ 51.53620148,   0.0798    ],
   [ 51.53620148,   0.0798    ],
   ..., 
   [ 51.54118347,  -0.08202313],
   [ 48.84996033,   2.32329845],
   [ 40.42570496,  -3.70100427]])

Here is my code:

def kdtree(search_points, vec_points):
mytree = scipy.spatial.cKDTree(search_points)
dist, indexes = mytree.query(vec_points)
return indexes, dist

result = kdtree(vec_array,search_array)

And the output:

(array([1361, 1339, 1339, ..., 1139, 1766, 1711]),
array([ 0.01365104,  0.00059667,  0.00059667, ...,  0.00151025,
         0.00754338,  0.00203098]))

The second array is clearly the distances but I can't work out what unit it is in, I'd be very grateful if somebody could enlighten me!


Solution

  • As kindly indicated by Warren in the comment above, the units are the same as in the input array.