[SciPy-User] It is quite confusing to use scipy.spatial.distance

江大伟 zw4131 at gmail.com
Mon May 30 08:26:13 EDT 2011


Thanks. This is an googd solusion.
But it is not the best solusion.

Using an uniform function to Computes the distance between
any-dimensional array. Scipy.spatial.distance.cdist() is a very good
function, and it can be extended to Computes the distance between a vector
and a vector as well as between a vector and n vectors. That would be
perfect !!.



2011/5/30 Pauli Virtanen <pav at iki.fi>

> On Mon, 30 May 2011 00:25:39 +0800, 江大伟 wrote:
> > I want to computes euclidean distance between a vector and 2 vector. For
> > example:
> >
> > A=numpy.array([0,0])
> >
> > B= numpy.array([[1,0],[0,1]])
> >
> > I want to computes euclidean distance between vector A and each vector
> > in matrix B.
> >
> > My expected result is the vector [1,1]
>
> In [9]: scipy.spatial.distance.cdist(A[numpy.newaxis,:], B, 'euclidean')
>
> Out[9]: array([[ 1.,  1.]])
>
> It works similarly as all other functions that support broadcasting.
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110530/32482fd9/attachment.html>


More information about the SciPy-User mailing list