Function distances::vectors::euclidean

source ·
pub fn euclidean<T: Number, U: Float>(x: &[T], y: &[T]) -> U
Expand description

Euclidean distance between two vectors.

Also known as the L2-norm, the Euclidean distance is defined as the square root of the sum of the squares 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::euclidean;

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 = euclidean(&x, &y);

assert!((distance - (27.0_f64).sqrt()).abs() <= f64::EPSILON);