chebyshev#
- scipy.spatial.distance.chebyshev(u, v, w=None)[source]#
Compute the Chebyshev distance.
The Chebyshev distance between real vectors \(u \equiv (u_1, \cdots, u_n)\) and \(v \equiv (v_1, \cdots, v_n)\) is defined as [1]
\[d_\textrm{chebyshev}(u,v) := \max_{1 \le i \le n} |u_i-v_i|\]If a (non-negative) weight vector \(w \equiv (w_1, \cdots, w_n)\) is supplied, the weighted Chebyshev distance is defined to be the weighted Minkowski distance of infinite order; that is,
\[\begin{split}\begin{align} d_\textrm{chebyshev}(u,v;w) &:= \lim_{p\rightarrow \infty} \left( \sum_{i=1}^n w_i | u_i-v_i |^p \right)^\frac{1}{p} \\ &= \max_{1 \le i \le n} 1_{w_i > 0} | u_i - v_i | \end{align}\end{split}\]- Parameters:
- u(…, N) array_like
Input vector.
- v(…, N) array_like
Input vector.
- w(…, N) array_like, optional
Weight vector. Default is
None, which gives all pairs \((u_i, v_i)\) the same weight1.0.
- Returns:
- chebyshevfloat or array
The Chebyshev distance between vectors u and v, optionally weighted by w.
Notes
Array API Standard Support
chebyshevhas support for Python Array API Standard compatible backends in addition to NumPy. The following combinations of backend and device (or other capability) are supported.Library
CPU
GPU
NumPy
✅
n/a
CuPy
n/a
✅
PyTorch
✅
✅
JAX
✅
✅
Dask
✅
n/a
See Array API coverage for more information.
References
Examples
>>> from scipy.spatial import distance >>> distance.chebyshev([1, 0, 0], [0, 1, 0]) 1.0 >>> distance.chebyshev([1, 1, 0], [0, 1, 0]) 1.0