bundles / scipy 1.18.0 / scipy / spatial / _kdtree / distance_matrix
function
scipy.spatial._kdtree:distance_matrix
source: /scipy/spatial/_kdtree.py:961
Signature
def distance_matrix(x, y, p = 2.0, threshold = 1000000)Summary
Compute the distance matrix.
Extended Summary
Returns the matrix of all pair-wise distances.
Parameters
x: (M, K) array_likeMatrix of M vectors in K dimensions.
y: (N, K) array_likeMatrix of N vectors in K dimensions.
p: float, 1 <= p <= infinityWhich Minkowski p-norm to use.
threshold: positive intIf
M * N * K>threshold, algorithm uses a Python loop instead of large temporary arrays.
Returns
result: (M, N) ndarrayMatrix containing the distance from every vector in
xto every vector iny.
Notes
Array API Standard Support
distance_matrix is not in-scope for support of Python Array API Standard compatible backends other than NumPy.
See dev-arrayapi for more information.
Examples
from scipy.spatial import distance_matrix
✓distance_matrix([[0,0],[0,1]], [[1,0],[1,1]])
✗array([[1. , 1.414],
[1.414, 1. ]])
Aliases
scipy.spatial.distance_matrix