Skip to main content

running_mean

Function running_mean 

Source
pub fn running_mean(data: &[f64], binwidth: usize) -> IgraphResult<Vec<f64>>
Expand description

Compute the running mean of a data vector.

For a data vector of length n and bin width w, returns a vector of length n - w + 1 where entry i is the mean of data[i..i+w].

§Errors

  • InvalidArgument if binwidth < 1.
  • InvalidArgument if data.len() < binwidth.

§Examples

use rust_igraph::running_mean;

let data = vec![1.0, 2.0, 3.0, 4.0, 5.0];
let result = running_mean(&data, 3).unwrap();
assert_eq!(result.len(), 3);
assert!((result[0] - 2.0).abs() < 1e-10); // mean(1,2,3)
assert!((result[1] - 3.0).abs() < 1e-10); // mean(2,3,4)
assert!((result[2] - 4.0).abs() < 1e-10); // mean(3,4,5)