Questions tagged [euclidean-distance]

the Euclidean distance or Euclidean metric is the "ordinary" distance between two points that one would measure with a ruler, and is given by the Pythagorean formula.

In mathematics, the Euclidean distance or Euclidean metric is the "ordinary" distance between two points that one would measure with a ruler, and is given by the Pythagorean formula. By using this formula as distance, Euclidean space (or even any inner product space) becomes a metric space. The associated norm is called the Euclidean norm.

http://en.wikipedia.org/wiki/Euclidean_distance

830 questions
620
votes
22 answers

How can the Euclidean distance be calculated with NumPy?

I have two points in 3D: (xa, ya, za) (xb, yb, zb) And I want to calculate the distance: dist = sqrt((xa-xb)^2 + (ya-yb)^2 + (za-zb)^2) What's the best way to do this with NumPy, or with Python in general? I have: import numpy a = numpy.array((xa…
Nathan Fellman
  • 108,984
  • 95
  • 246
  • 308
41
votes
2 answers

Compare similarity algorithms

I want to use string similarity functions to find corrupted data in my database. I came upon several of them: Jaro, Jaro-Winkler, Levenshtein, Euclidean and Q-gram, I wanted to know what is the difference between them and in what situations…
41
votes
6 answers

Minimum Euclidean distance between points in two different Numpy arrays, not within

I have two arrays of x-y coordinates, and I would like to find the minimum Euclidean distance between each point in one array with all the points in the other array. The arrays are not necessarily the same size. For example: xy1=numpy.array( [[ …
fideli
  • 2,772
  • 1
  • 20
  • 24
40
votes
4 answers

Vector Space Model: Cosine Similarity vs Euclidean Distance

I have corpora of classified text. From these I create vectors. Each vector corresponds to one document. Vector components are word weights in this document computed as TFIDF values. Next I build a model in which every class is presented by a single…
Anton Ashanin
  • 1,789
  • 5
  • 27
  • 42
26
votes
5 answers

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…
pacodelumberg
  • 1,964
  • 4
  • 21
  • 30
25
votes
2 answers

Is "norm" equivalent to "Euclidean distance"?

I am not sure whether "norm" and "Euclidean distance" mean the same thing. Please could you help me with this distinction. I have an n by m array a, where m > 3. I want to calculate the Eculidean distance between the second data point a[1,:] to all…
J_yang
  • 2,179
  • 3
  • 24
  • 47
20
votes
4 answers

Efficiently Calculating a Euclidean Distance Matrix Using Numpy

I have a set of points in 2-dimensional space and need to calculate the distance from each point to each other point. I have a relatively small number of points, maybe at most 100. But since I need to do it often and rapidly in order to determine…
Wes Modes
  • 1,687
  • 2
  • 18
  • 30
15
votes
3 answers

Efficient calculation of euclidean distance

I have a MxN array, where M is the number of observations and N is the dimensionality of each vector. From this array of vectors, I need to calculate the mean and minimum euclidean distance between the vectors. In my mind, this requires me to…
japata
  • 319
  • 1
  • 9
14
votes
6 answers

Multidimensional Euclidean Distance in Python

I want to calculate the Euclidean distance in multiple dimensions (24 dimensions) between 2 arrays. I'm using numpy-Scipy. Here is my code: import numpy,scipy; A=numpy.array([116.629, 7192.6, 4535.66, 279714, 176404, 443608, 295522, 1.18399e+07,…
garak
  • 4,135
  • 9
  • 34
  • 55
13
votes
5 answers

Fastest way to calculate the distance between two CGPoints?

Distance between two points: sqrt((x1-x2)^2 + (y1-y2)^2) Is there a way to do this math faster in objective-C ? EDIT: I think I need to clarify above. I wrote the formula above just to clarify what formula I am using to calculate the distance. ^ is…
xcoder
  • 917
  • 2
  • 11
  • 24
13
votes
1 answer

Calculate signed distance between point and rectangle

I'm trying to write a function in GLSL that returns the signed distance to a rectangle. The rectangle is axis-aligned. I feel a bit stuck; I just can't wrap my head around what I need to do to make it work. The best I came up with is this: float…
tenfour
  • 33,679
  • 12
  • 73
  • 135
13
votes
6 answers

Find the shortest distance between a point and line segments (not line)

I have set of line segments (not lines), (A1, B1), (A2, B2), (A3, B3), where A,B are ending points of the line segment. Each A and B has (x,y) coordinates. QUESTION: I need to know the shortest distance between point O and line segments as shown in…
Spider
  • 826
  • 3
  • 14
  • 34
13
votes
2 answers

Efficiently compute pairwise squared Euclidean distance in Matlab

Given two sets of d-dimensional points. How can I most efficiently compute the pairwise squared euclidean distance matrix in Matlab? Notation: Set one is given by a (numA,d)-matrix A and set two is given by a (numB,d)-matrix B. The resulting…
matheburg
  • 1,869
  • 1
  • 14
  • 38
13
votes
3 answers

Distance calculation between rows in Pandas Dataframe using a distance matrix

I have the following Pandas DataFrame: In [31]: import pandas as pd sample = pd.DataFrame({'Sym1': ['a','a','a','d'],'Sym2':['a','c','b','b'],'Sym3':['a','c','b','d'],'Sym4':['b','b','b','a']},index=['Item1','Item2','Item3','Item4']) In [32]:…
Clayton
  • 1,345
  • 5
  • 17
  • 34
12
votes
5 answers

Efficient and precise calculation of the euclidean distance

Following some online research (1, 2, numpy, scipy, scikit, math), I have found several ways for calculating the Euclidean Distance in Python: # 1 numpy.linalg.norm(a-b) # 2 distance.euclidean(vector1, vector2) #…
user6167676
1
2 3
55 56