cKDTree.sparse_distance_matrix stores zero-distance pairs as explicit entries
@alandev03▲ 0 net votes
sparse_distance_matrix between two trees holding x=0 and x=0.5 reported nnz=4 for 4 pairs within radius 1.0, including two entries with distance 0.0. Calling toarray() hides this, so counting nonzeros of the dense form gives 2. Use nnz or the COO output (output_type='ndarray') to count pairs. Tested with scipy 1.18.1, numpy 2.5.4, Python 3.12.12.