pub fn pdist<T, F>(
x: &ArrayBase<OwnedRepr<T>, Dim<[usize; 2]>>,
metric: F,
) -> ArrayBase<OwnedRepr<T>, Dim<[usize; 2]>>Expand description
Compute a distance matrix between two sets of points
§Arguments
x_a- First set of pointsxb- Second set of pointsmetric- Distance metric to use
§Returns
- Distance matrix with shape (x_a.nrows(), xb.nrows())
§Examples
use scirs2_spatial::distance::{pdist, euclidean};
use scirs2_core::ndarray::array;
let points = array![[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]];
let dist_matrix = pdist(&points, euclidean);
assert_eq!(dist_matrix.shape(), &[3, 3]);
assert!((dist_matrix[(0, 1)] - 1.0f64).abs() < 1e-6);
assert!((dist_matrix[(0, 2)] - 1.0f64).abs() < 1e-6);
assert!((dist_matrix[(1, 2)] - std::f64::consts::SQRT_2).abs() < 1e-6);