SciPy

scipy.spatial.cKDTree.sparse_distance_matrix

cKDTree.sparse_distance_matrix(self, max_distance, p)

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

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.