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

941 questions
776
votes
26 answers

How can the Euclidean distance be calculated with NumPy?

I have two points in 3D space: a = (ax, ay, az) b = (bx, by, bz) I want to calculate the distance between them: dist = sqrt((ax-bx)^2 + (ay-by)^2 + (az-bz)^2) How do I do this with NumPy? I have: import numpy a = numpy.array((ax, ay, az)) b =…
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319
45
votes
9 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
  • 3,213
  • 5
  • 23
  • 24
43
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…
Ali
  • 808
  • 2
  • 11
  • 20
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,817
  • 5
  • 30
  • 43
33
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
  • 2,214
  • 4
  • 25
  • 32
31
votes
5 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
  • 2,024
  • 2
  • 22
  • 40
27
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,672
  • 8
  • 32
  • 61
21
votes
7 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,713
  • 9
  • 39
  • 56
21
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
  • 967
  • 3
  • 14
  • 35
21
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,525
  • 5
  • 19
  • 35
19
votes
3 answers

Calculate Euclidean distance between 4-dimensional vectors

Let's say I have two 4-dimensional vectors (i.e. a and b) as follows: a = {a1, a2, a3, a4} b= {b1, b2, b3, b4} How do I compute the Euclidean distance between these vectors?
user3583442
  • 209
  • 1
  • 2
  • 4
16
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
  • 36,141
  • 15
  • 83
  • 142
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
  • 329
  • 1
  • 9
15
votes
3 answers

Euclidean distance between two n-dimensional vectors

What's an easy way to find the Euclidean distance between two n-dimensional vectors in Julia?
JobJob
  • 3,822
  • 3
  • 33
  • 34
14
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
  • 967
  • 2
  • 11
  • 24
1
2 3
62 63