Function distances::vectors::minkowski

source ·
pub fn minkowski<T: Number, U: Float>(p: i32) -> impl Fn(&[T], &[T]) -> U
Expand description

General Lp-norm between two vectors.

The Lp-norm is defined as the pth root of the sum of the pth powers of the absolute differences between the corresponding elements of the two vectors.

See the crate::vectors module documentation for information on this function’s potentially unexpected behaviors

§Arguments

  • x - The first slice of Numbers.
  • y - The second slice of Numbers.

§Examples

use distances::vectors::minkowski;

let metric = minkowski(3);

let x: Vec<f64> = vec![1.0, 2.0, 3.0];
let y: Vec<f64> = vec![4.0, 5.0, 6.0];

let distance: f64 = metric(&x, &y);
assert!((distance - (81.0_f64).cbrt()).abs() <= 1e-12);