pub fn eye<T>(n: usize) -> Array<T, Ix2>
Expand description
Create an identity matrix
§Arguments
n
- Number of rows and columns in the square identity matrix
§Returns
An nxn identity matrix
§Examples
use scirs2_core::ndarray_ext::matrix::eye;
let id3 = eye::<f64>(3);
assert_eq!(id3.shape(), &[3, 3]);
assert_eq!(id3[[0, 0]], 1.0);
assert_eq!(id3[[1, 1]], 1.0);
assert_eq!(id3[[2, 2]], 1.0);
assert_eq!(id3[[0, 1]], 0.0);