identity

Returns a square slice of element type E with ones on the main diagonal and zeros elsewhere.

pure
identity
(
E = double
)
(
size_t n
)

Parameters

n size_t

number of rows and columns

Return Value

Type: auto

new identity slice

Examples

assert(identity(2) == [[1.0, 0.0],
                       [0.0, 1.0]]);

Meta