Computing Chebyshev distance using Python

Given two n-dimensional points, the Chebyshev distance returns the maximum of axis-wise differences. The Python example finds the Chebyshev distances between two 2-dimensional points and two 3-dimensional points.

Distance Calculcations Updated 22 Jul 2025 1 min read

Overview

  • The Chebyshev distance between two points in real space is given by the maximum of the axis differences.
  • Chebyshev distance between two points of n-dimensions is given by

Chebyshev distance(P1, P2) = max(|xi-yi|) where i varies from 1 to n.

  • The SciPy function chebyshev() from the scipy.spatial.distance returns the Chebyshev distance between two points P1 and P2 in n-dimensions.
  • The Chebyshev distance is also called as the Chessboard distance.
  • Since Chebyshev distance deals with points from real space, when counting movements in a grid structure like chess board the discrete intervals need to be taken. Each cell is considered as 1 unit when movements are counted. In this context, Chebyshev distance is also called as chessboard distance. The Chebyshev distance gives the minimum number of moves required to go from one cell to another cell in the grid.

Chebyshev Distance using Python

Example

python
# Example Python program that finds the Chebyshev distance

            # between two given points in real space

            import scipy.spatial.distance as dist

# Chebyshev distance between points on a 2-d plane

            point1 = (1, 1)

            point2 = (3, 2)

chebyshev_distance = dist.chebyshev(point1, point2)

            print("Chebyshev_distance:{}".format(chebyshev_distance))

# Chebyshev distance between points on a 3-d space

            point1 = (1, 1, 4)

            point2 = (3, 2, 7)

chebyshev_distance = dist.chebyshev(point1, point2)

            print("Chebyshev distance:{}".format(chebyshev_distance))

Output

Output
Chebyshev distance:2

            Chebyshev distance:3