eye

Function eye 

Source
pub fn eye<T>(n: usize) -> Array<T, Ix2>
where T: Clone + Zero + One,
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);