ManhattanDistance[u,v]
gives the Manhattan or "city block" distance between vectors u and v.
ManhattanDistance
ManhattanDistance[u,v]
gives the Manhattan or "city block" distance between vectors u and v.
Details
- Manhattan distance is effectively the sum of of differences across all dimensions.
- ManhattanDistance[u,v] is equivalent to Total[Abs[u-v]]. »
Examples
open all close allBasic Examples (2)
Scope (2)
Applications (2)
Cluster data using Manhattan distance:
FindClusters[{{2, 3}, {5, 10}, {4, 5}, {2, 2}}, DistanceFunction -> ManhattanDistance]Demonstrate the triangle inequality:
d1 = ManhattanDistance[{a, b}, {a, c}]d2 = ManhattanDistance[{a, c}, {d, c}]d3 = ManhattanDistance[{a, b}, {d, c}]Simplify[d3 <= d1 + d2]Properties & Relations (5)
Manhattan distance is a sum of absolute differences:
ManhattanDistance[{a, b, c}, {x, y, z}]Total[Abs[{a, b, c} - {x, y, z}]]ManhattanDistance is equivalent to a Norm of a difference:
ManhattanDistance[{a, b, c}, {x, y, z}]Norm[{a, b, c} - {x, y, z}, 1]ManhattanDistance is greater than or equal to ChessboardDistance:
u = {a, b, c};
v = {x, y, z};Simplify[ManhattanDistance[u, v] ≥ ChessboardDistance[u, v]]BrayCurtisDistance is a ratio of Manhattan distances:
u = {a, b, c};
v = {x, y, z};ManhattanDistance[u, v] / ManhattanDistance[u, -v]BrayCurtisDistance[u, v]MeanDeviation as a scaled ManhattanDistance from the Mean:
data = {a, b, c}mean = Table[Mean[data], {Length[data]}]MeanDeviation[data]ManhattanDistance[data, mean] / Length[data]Tech Notes
Related Guides
History
Text
Wolfram Research (2007), ManhattanDistance, Wolfram Language function, https://reference.wolfram.com/language/ref/ManhattanDistance.html.
CMS
Wolfram Language. 2007. "ManhattanDistance." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ManhattanDistance.html.
APA
Wolfram Language. (2007). ManhattanDistance. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ManhattanDistance.html
BibTeX
@misc{reference.wolfram_2026_manhattandistance, author="Wolfram Research", title="{ManhattanDistance}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/ManhattanDistance.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_manhattandistance, organization={Wolfram Research}, title={ManhattanDistance}, year={2007}, url={https://reference.wolfram.com/language/ref/ManhattanDistance.html}, note=[Accessed: 12-June-2026]}