Manhattan distance
Manhattan distance is the sum of the absolute differences between corresponding coordinates of two points or vectors.
Classic Computer Science Problems in Swift: Essential techniques for practicing programmers
Manhattan distance is the sum of the absolute differences between corresponding coordinates of two points.
- How it is used
- Guides A* search toward a goal in a four-direction maze.
- How deep it goes
- Defines the row-and-column calculation and implements it in Swift, then explains admissibility without a formal proof.
- Examples
- Uses Manhattan street blocks, maze locations, a grid figure, and a Swift distance function.
- What you can do after
- Build it from scratch as a Swift heuristic for four-direction A* maze search.
Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI
Manhattan distance is the sum of the absolute coordinate differences between two points.
- How it is used
- Creates geographical machine-learning features that represent proximity and urban travel patterns.
- How deep it goes
- Defines the metric, contrasts it with Euclidean distance, and applies it to coordinates and nearest-neighbor queries.
- Examples
- Uses Tokyo Airbnb coordinates, the Imperial Palace, and nearby transportation and facility categories.
- What you can do after
- Apply it via scikit-learn KDTree and coordinate transformations to create proximity features.
Data Without Labels
Manhattan distance is the sum of absolute coordinate differences between two points, corresponding to movement along perpendicular axes.
- How it is used
- Uses absolute coordinate differences to measure similarity or distance between observations during clustering.
- How deep it goes
- Defines the grid-path formula, contrasts L1 with L2, and notes high-dimensional preference without detailing implementation.
- Examples
- Uses coordinate points, grid-like movement, and centroid or hierarchical clustering as application contexts.
- What you can do after
- Apply it as a distance metric when comparing clustering choices for a dataset.
Outlier Detection in Python
Manhattan distance is the sum of the absolute coordinate-wise differences between two points.
- How it is used
- Uses coordinate-wise differences to compare records, including mixed datasets and some outlier-detection workflows.
- How deep it goes
- Defines the metric, compares its weighting with Euclidean distance, and demonstrates implementation; it stops short of a full detector.
- Examples
- Uses one-hot encoded color and weight rows, pairwise distance tables, and Python calls to manhattan_distances.
- What you can do after
- Apply it via scikit-learn to calculate distances between numeric or one-hot encoded records.
Read how Outlier Detection in Python explains Manhattan distance →
Related concepts
- Euclidean distancecontrasts with · Euclidean distance is the straight-line distance between two points in Euclidean space, calculated as the square root of the sum of squared differences between corresponding coordinates.
- minkowski distanceequivalent to · Minkowski distance is a parameterized metric between points based on a positive-order norm, including Manhattan and Euclidean distance as special cases.
- distancecontrasts with · Distance is a measure of separation between points or entities in a defined space or context.
- heuristickind of · A heuristic is a practical rule or approximate method for guiding judgment, search, or problem solving without guaranteeing an exact or optimal result.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.



