[SciPy-Dev] Distance functions

Jaime Fernández del Río jaime.frio at gmail.com
Tue Feb 4 19:38:41 EST 2014


I plan to have a first fully functional version of the new distance module
for scipy.spatial during this week, see
https://github.com/scipy/scipy/pull/3163. The main feature of this new
implementation is broadcasting support, so that you can compute multiple
distances with a single function call, e.g.:

>>> import scipy.spatial.umath_distance as udist
>>> import numpy as np
>>> u = np.random.rand(4, 3)
>>> v = np.random.rand(4, 3)
>>> udist.euclidean(u, v)
array([ 0.77251733,  0.93810526,  0.81122198,  0.87690279])

Or even all pairwise distances:

>>> v = np.random.rand(5, 3)
>>> udist.euclidean(u[:, None, :], v)
array([[ 1.14347901,  0.38593543,  0.83640822,  0.87086049,  1.04517368],
       [ 0.92483017,  0.71607629,  0.93401924,  0.5825294 ,  0.92202074],
       [ 0.72273632,  0.81842944,  1.0669884 ,  0.85308725,  0.83356081],
       [ 0.22143423,  0.81656032,  0.78084203,  0.90199059,  0.35111241]])

Although this is the main new feature, now is the right time to ask for
that other feature of distance you have been missing all this time, but
were afraid to ask for. I have thrown a few of my own:

   1. greatcircle, to compute distances on the surface of a sphere.
   2. weighted hamming, city block, euclidean and sqeuclidean distances
   3. pminkowski and pwminkowski, to compute the Minkowski and weighted
   Minkowski distances without the final raising to the power 1/p, i.e. what
   sqeuclidean is to euclidean, this are to minkowski.

Any suggestions or comments are very welcome!

Jaime

-- 
(\__/)
( O.o)
( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes
de dominación mundial.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20140204/e47a0365/attachment.html>


More information about the SciPy-Dev mailing list