I'm trying to calculate the covariance of a data frame in Rust. The ndarray_stats crate defines such a function for arrays, and I can produce an array from a DataFrame using to_ndarray. The compiler is happy if I use the example in the documentation (a), but if I try to use it on an Array2 produced from a DataFrame, this doesn't work:
use polars::prelude::*;
use ndarray_stats::CorrelationExt;
fn cov(df: &DataFrame) -> Vec<f64> {
// Both of these are Array2<f64>s
let mat = df.to_ndarray::<Float64Type>().unwrap();
let a = arr2(&[[1., 3., 5.], [2., 4., 6.]]);
let x = a.cov(1.).unwrap();
let y = mat.cov(1.).unwrap();
}
|
22 | let y = mat.cov(1.).unwrap();
| ^^^ method not found in `ndarray::ArrayBase<ndarray::data_repr::OwnedRepr<f64>, ndarray::dimension::dim::Dim<[usize; 2]>>`
Why does the compiler allow the definition of x but not y? How can I fix the code such that y can be assigned?