pub fn cov<T>(
array: ArrayView<'_, T, Ix2>,
ddof: usize,
) -> Result<Array<T, Ix2>, &'static str>
Expand description
Calculate the covariance matrix of a 2D array
§Arguments
array
- The input 2D array where rows are observations and columns are variablesddof
- Delta degrees of freedom (default 1)
§Returns
The covariance matrix
§Examples
use ndarray::array;
use scirs2_core::ndarray_ext::stats::cov;
let data = array![
[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0],
[7.0, 8.0, 9.0],
[10.0, 11.0, 12.0]
];
let covmatrix = cov(data.view(), 1).unwrap();
assert_eq!(covmatrix.shape(), &[3, 3]);
This function is equivalent to NumPy
’s np.cov
function.