Manhattan Distance Calculator

Compare vectors, analyse datasets, rank nearest neighbours, apply feature scaling, inspect every absolute difference, and export clear machine learning distance results instantly with confidence.

Calculator Inputs

Vector input

Accepts CSV, spaces, lines, semicolons, or JSON arrays.
Both vectors must use equal dimensions.
FeatureVector AVector BWeight

Dataset input

A header row is detected automatically when present.
Maximum file size is 2 MB.

Or column

Feature scaling

Dataset scaling is learned from feature columns.

Missing values and weights

Calculations run locally on your PHP server.

Formula Used

Standard: D(A, B) = Σ |Ai − Bi|
Weighted: Dw(A, B) = Σ wi|Ai − Bi|
Normalised: Σ|Ai − Bi| ÷ Σ(|Ai| + |Bi|)

Manhattan distance adds absolute feature differences. It avoids squared differences entirely. Each dimension contributes independently to the final distance score.

How to Use

  1. Choose vector, dataset, or matrix mode.
  2. Select a distance variant and scaling method.
  3. Enter vectors or paste a structured dataset.
  4. Configure weights, missing values, and KNN settings.
  5. Submit, inspect details, then export the results.

Example Data

ExampleVector AVector BCalculationDistance
Basic[1, 2, 3][4, 0, 5]3 + 2 + 27
Identical[2, 2][2, 2]0 + 00
Negative values[-2, 4][3, -1]5 + 510

Machine Learning Applications

K-nearest neighbours

Rank training samples by absolute differences. Select the closest observations. Their classes can determine the query prediction reliably.

Clustering

Measure separation without squared penalties. Compare within-cluster and between-cluster distances. Scaled features improve meaningful cluster comparisons across dimensions.

Anomaly detection

Compare new points against reference observations. Large distances can indicate unusual behaviour. Threshold selection still requires validation using representative training data.

Frequently Asked Questions

What is Manhattan distance?

It sums absolute coordinate differences between two points. The metric resembles city-block travel. Movement follows feature axes instead of diagonal shortcuts.

Why scale features first?

Large numeric ranges can dominate the distance. Scaling balances feature influence. Choose parameters learned from training data whenever possible.

How does weighted Manhattan distance work?

Each feature difference receives a non-negative weight. Larger weights increase feature influence. Normalised weights can simplify interpretation across repeated experiments.

Can the calculator perform KNN classification?

Yes, dataset mode ranks every training observation. Top neighbours receive votes. Distance-weighted voting gives closer samples greater predictive influence.

What happens with missing values?

You can reject, ignore, or replace them. Mean replacement uses available feature values. Review warnings before trusting any imputed distance calculation.

Is Manhattan distance always between zero and one?

Standard distance has no fixed upper bound. Normalised distance stays bounded here. Its denominator uses both vectors' total absolute magnitude.

How is Euclidean distance different?

Euclidean distance squares differences before aggregation. Manhattan distance uses absolute differences. Manhattan can be more robust against isolated extremes.

Can categorical columns be included?

Only the selected label column may remain categorical. Feature columns must be numeric. Encode categories numerically before using them as features.

What does the matrix mode provide?

It compares every dataset row with others. The coloured table highlights separation. Labelled data also receives within-class and between-class summaries.

Related Calculators

K-Means Clustering CalculatorEuclidean Distance CalculatorCosine Similarity CalculatorSilhouette Score CalculatorDavies-Bouldin Index CalculatorCalinski-Harabasz Score CalculatorCluster Centroid CalculatorWithin-Cluster Sum of Squares CalculatorElbow Method CalculatorDBSCAN Neighbourhood Calculator

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.