SciPy

scipy.spatial.cKDTree.sparse_distance_matrix

cKDTree.sparse_distance_matrix(self, other, max_distance, p=2.)

Compute a sparse distance matrix

Computes a distance matrix between two KDTrees, leaving as zero any distance greater than max_distance.

Parameters:

other : cKDTree

max_distance : positive float

p : float, 1<=p<=infinity

Which Minkowski p-norm to use.

Returns:

result : dok_matrix

Sparse matrix representing the results in “dictionary of keys” format. FIXME: Internally, built as a COO matrix, it would be more efficient to return this COO matrix.