Skip to contents

Creates a diagonal matrix from a 1-D array.

Usage

nv_diag(operand)

Arguments

operand

(arrayish)
A 1-D array of length n whose elements become the diagonal entries.

Value

arrayish
An n x n matrix with x on the diagonal and zeros elsewhere.

Examples

nv_diag(nv_array(c(1, 2, 3)))
#> AnvlArray
#>  1 0 0
#>  0 2 0
#>  0 0 3
#> [ CPUf32{3,3} ]