I have a practice problem that I am working on (artificial intelligence), but am unable to calculate the Euclidean and Manhattan distances by hand using the following values:

x1:  1.0, 3.2, 4.8, 0.1, 3.2, 0.6, 2.2, 1.1
x2:  0.1, 5.2, 1.9, 4.2, 1.9, 0.1, 0.1, 6.0

Could somebody kindly explain how I would go about working out the Euclidean and Manhattan distances by hand as I have no idea where to begin, so some pointers in the right direction would be highly appreciated!

Please note that I'm not asking to have it done for me; I am interested in the workings behind it so that I know how to go about it.


Euclidean: Take the square root of the sum of the squares of the differences of the coordinates.

For example, if $x=(\color{darkgreen}a,\color{maroon}b)$ and $y=(\color{darkgreen}c,\color{maroon}d)$, the Euclidean distance between $x$ and $y$ is

$\sqrt{(\color{darkgreen}a-\color{darkgreen}c)^2+(\color{maroon}b-\color{maroon}d)^2 }$.

Manhattan: Take the sum of the absolute values of the differences of the coordinates.

For example, if $x=(\color{darkgreen}a,\color{maroon}b)$ and $y=(\color{darkgreen}c,\color{maroon}d)$, the Manhattan distance between $x$ and $y$ is

$ {|\color{darkgreen}a-\color{darkgreen}c|+|\color{maroon}b-\color{maroon}d| }$.

For your vectors, it's the same thing except you have more coordinates.


This is an old post, but just want to explain that the squaring and square rooting in the euclidean distance function is basically to get absolute values of each dimension assessed. Manhattan distance just bypasses that and goes right to abs value (which if your doing ai, data mining, machine learning, may be a cheaper function call then pow'ing and sqrt'ing.) I've seen debates about using one way vs the other when it gets to higher level stuff, like comparing least squares or linear algebra (?). Manhattan distance is easier to calculate by hand, bc you just subtract the values of a dimensiin then abs them and add all the results. Euclidean distance is harder by hand bc you're squaring anf square rooting. So some of this comes down to what purpose you're using it for.




Edited: eucledian distance between two points

P=[p0,p1,p2..pn]  and  Q=[q1,q2,...qn}

$D(p,q)=\sqrt(((sum((qi-pi)^2)$)) for i=1....n manhattan distance is sum of absolute differences between points,see wikipedia


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.