Function distances::vectors::minkowski_p
source · pub fn minkowski_p<T: Number, U: Float>(p: i32) -> impl Fn(&[T], &[T]) -> U
Expand description
General (Lp-norm)^p between two vectors.
This is defined as the sum of the pth powers of the absolute differences between the corresponding elements of the two slices.
See the crate::vectors
module documentation for information on this
function’s potentially unexpected behaviors
§Arguments
x
- The first slice ofNumber
s.y
- The second slice ofNumber
s.
§Examples
use distances::vectors::minkowski_p;
let metric = minkowski_p(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).abs() <= 1e-12);