我正在尝试计算 Rust 中数据框的协方差。ndarray_statscrate 为数组定义了这样一个函数,我可以从DataFrameusing生成一个数组to_ndarray。如果我使用文档中的a示例(Array2DataFrame
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]>>`
为什么编译器允许定义xbut not y?如何修复y可以分配的代码?