Function distances::vectors::manhattan

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

Manhattan distance between two vectors.

Also known as the L1-norm or the taxicab distance, the Manhattan distance is defined as the sum 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::manhattan;

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

assert!((distance - 9.0).abs() <= f64::EPSILON);