[SciPy-User] sparse distance matrix ?

Sturla Molden sturla.molden at gmail.com
Sun Apr 6 19:50:23 EDT 2014


<josef.pktd at gmail.com> wrote:

>> scipy.spatial.cKDTree can do this.
> 
> Thanks Sturla, I forgot to look there, because I don't need repeated look-up.

You do need repeated lookups in the case of distance matrix. There are
potentially n*(n-1)/2 distances to compute. But you don't need all of
these, if they are out of the bound you specity. So with a kd-tree you can
avoid computing distances you don't need, by rejecting a whole branch of
the tree at once. That can be considerably faster than brute-forcing all
pair-wise distances.

Sturla




More information about the SciPy-User mailing list