Manhattan Distance
Distance measured along axes at right angles (taxicab geometry).
Formula
Variables
Example
Between (0,0) and (3,4): d = 7
How it works
Manhattan distance adds up the absolute differences between matching coordinates, so it measures how far apart two points are if you can only move parallel to the axes. It comes from the idea of traveling on a grid of streets, where diagonal shortcuts are not allowed, so you must count each horizontal and vertical step separately. Taking absolute values ensures each coordinate contributes a nonnegative amount, no matter which point is larger in that dimension.
When to use it
Use Manhattan distance when movement is constrained to grid-like paths, such as city blocks, robotics on a rectangular map, or feature-space comparisons in data science. It is also useful when you want a distance measure that is less sensitive to large differences in one diagonal direction than straight-line distance.
Worked example, step by step
Find the Manhattan distance between points (2, -1) and (7, 3). Step 1: Write the coordinates by dimension: a = (2, -1), b = (7, 3) Step 2: Compute each absolute difference: |2 - 7| = 5 and |-1 - 3| = 4 Step 3: Add the results: d = 5 + 4 Step 4: Final answer: d = 9
Common mistakes to avoid
- using ordinary straight-line distance instead of adding coordinate-by-coordinate absolute differences
- forgetting the absolute value and letting negative differences cancel out
- mixing up the coordinates or omitting a dimension when summing
Did You Know?
Named after the grid layout of Manhattan streets.
Share this formula
More in Data Science & ML
View allMean Squared Error (MSE)
BasicAverage of squared differences between predicted and actual values.
Root Mean Squared Error (RMSE)
BasicSquare root of MSE, in the same units as the target variable.
Mean Absolute Error (MAE)
BasicAverage of absolute differences between predictions and actual values.
Coefficient of Determination (R²)
IntermediateProportion of variance in the target explained by the model.
Classification Accuracy
BasicFraction of predictions that are correct.
Precision
IntermediateOf all positive predictions, the fraction that were correct.