eye

Identity matrix.

@safe pure nothrow @nogc
Slice!(RCI!T, 2)
eye
(
T = double
)
(
size_t n
,
size_t m = 0
)
if (
isFloatingPoint!T ||
isComplex!T
)
out (i) { assert (i.length!0 == n); assert (i.length!1 == (m == 0 ? n : m)); }

Parameters

n size_t

number of columns

m size_t

optional number of rows, default n Results: Matrix which is 1 on the diagonal and 0 elsewhere

Examples

Real numbers

import mir.ndslice;
import mir.math;

assert(eye(1)== [
    [1]]);
assert(eye(2)== [
    [1, 0],
    [0, 1]]);
assert(eye(3)== [
    [1, 0, 0],
    [0, 1, 0],
    [0, 0, 1]]);
assert(eye(1,2) == [
    [1,0]]);
assert(eye(2,1) == [
    [1],
    [0]]);

Meta