Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python numpy euclidean distance calculation between matrices of row vectors

I am new to Numpy and I would like to ask you how to calculate euclidean distance between points stored in a vector.

Let's assume that we have a numpy.array each row is a vector and a single numpy.array. I would like to know if it is possible to calculate the euclidean distance between all the points and this single point and store them in one numpy.array.

Here is an interface:

points #2d list of row-vectors singlePoint #one row-vector  listOfDistances= procedure( points,singlePoint) 

Can we have something like this? Or is it possible to have one command to have the single point as a list of other points and at the end we get a matrix of distances?

Thanks

like image 325
pacodelumberg Avatar asked Dec 06 '10 21:12

pacodelumberg


People also ask

How do you find the Euclidean distance between two matrices?

The Euclidean distance is simply the square root of the squared differences between corresponding elements of the rows (or columns).

How do you find the distance between two matrices?

If we have two matrices A,B. Distance between A and B can be calculated using Singular values or 2 norms. You may use Distance =|(fnorm(A)−fnorm(B))| where fnorm = sq root of sum of squares of all singular values.


1 Answers

To get the distance you can use the norm method of the linalg module in numpy:

np.linalg.norm(x - y) 
like image 101
Christian Avatar answered Sep 28 '22 12:09

Christian