scialg 0.3.0

A collection of scientific algorithms
Documentation
1
2
3
4
5
6
7
8
9
10
11
//! Filter onedimensional data

/// Compute the moving average of *xs* with a window size of *k*
///
/// # Reference
///  - [Wikipedia: Moving average](https://en.wikipedia.org/wiki/Moving_average)
pub fn moving_average(xs: &[f64], k: usize) -> Vec<f64> {
    xs.windows(k)
        .map(|w| w.iter().sum::<f64>() / k as f64)
        .collect()
}