What's the most idiomatic way to get the Rust vec equivalent of this Python code?
import numpy as np
a = np.arange(5)
a_diff = np.diff(a) # this is the thing I'm trying to emulate in Rust
print(a_diff) # [1 1 1 1]
I can figure out multiple unsatisfactory ways of doing this, but I figure there's got to be a clean one-liner approach using iter()
, right?
let a: Vec<f64> = (0..5).collect::<Vec<i64>>().iter().map(|x| *x as f64).collect();
let a_diff = ???