Skip to content

Instantly share code, notes, and snippets.

@dineshadepu
Last active November 27, 2017 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dineshadepu/abadfd1f0c7aeeb307edc65270c9fcdf to your computer and use it in GitHub Desktop.
Save dineshadepu/abadfd1f0c7aeeb307edc65270c9fcdf to your computer and use it in GitHub Desktop.
l2 norm implemented in Rust and Python
x = array([1, 2, 3, 4, 5, 6])
y = np.arange(0, 6, 1)
np.linalg.norm(x-y, ord=2)
# 2.4494897427831779
fn main() {
let x = vec![1f32, 2., 3., 4., 5., 6.];
let y = vec![0f32, 1., 2., 3., 4., 5.];
let p = (x.iter().zip(y.iter()).fold(0., |sum, (&ex, &ey)| sum + ((ex - ey).abs()).powf(2.))).powf(1./2.);
println!("{:.32}", p);
}
// 2.4494898319244384765625
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment