scipy.spatial.distance.
braycurtis#
- scipy.spatial.distance.braycurtis(u, v, w=None)[source]#
Compute the Bray-Curtis distance between two vectors.
Bray-Curtis distance is defined as
\[\sum{|u_i-v_i|} / \sum{|u_i+v_i|}\]The Bray-Curtis distance is in the range [0, 1] if all coordinates are positive, and is undefined if the inputs are of length zero.
- Parameters:
- u(…,N) array_like
Input array.
- v(…,N) array_like
Input array.
- w(…,N) array_like, optional
The weights for each value in u and v. Default is None, which gives each value a weight of 1.0
- Returns:
- braycurtisfloat or array
The Bray-Curtis distance between 1-D arrays u and v.
Notes
Array API Standard Support
braycurtishas 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.
Examples
>>> from scipy.spatial import distance >>> distance.braycurtis([1, 0, 0], [0, 1, 0]) 1.0 >>> distance.braycurtis([1, 1, 0], [0, 1, 0]) 0.33333333333333331