Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Euclidean distance between two n-dimenstional vectors

What's an easy way to find the Euclidean distance between two n-dimensional vectors in Julia?

like image 385
JobJob Avatar asked Sep 18 '14 00:09

JobJob


People also ask

How do you find the Euclidean distance in n dimensions?

The Euclidean distance between 2 cells would be the simple arithmetic difference: xcell1 - xcell2 (eg. APHWcell1 = 1.11603 ms and APHWcell10 = 0.97034 ms; they are (1.11603 - 0.97034) = 0.14569 ms apart).

How do you find the Euclidean distance between two vectors?

Euclidean distance is calculated as the square root of the sum of the squared differences between the two vectors.

What is Euclidean distance in 3d space?

The Euclidean distance between two points in either the plane or 3-dimensional space measures the length of a segment connecting the two points. It is the most obvious way of representing distance between two points.


1 Answers

Here is a simple way

n = 10
x = rand(n)
y = rand(n)
d = norm(x-y)  # The euclidean (L2) distance

For Manhattan/taxicab/L1 distance, use norm(x-y,1)

like image 121
IainDunning Avatar answered Sep 27 '22 19:09

IainDunning