Function distances::vectors::euclidean_sq
source · pub fn euclidean_sq<T: Number, U: Number>(x: &[T], y: &[T]) -> U
Expand description
Squared Euclidean distance between two vectors.
Also known as the squared L2-norm, the squared Euclidean distance is defined as 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 ofNumber
s.y
- The second slice ofNumber
s.
§Examples
use distances::vectors::euclidean_sq;
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_sq(&x, &y);
assert!((distance - 27.0).abs() <= f64::EPSILON);