Skip to contents

Extracts the diagonal elements from a 2-D array.

Usage

nv_extract_diag(x)

Arguments

x

(arrayish)
One input, with exactly 2 axes. Can be any data type. An R value materializes at its default data type.

Value

(arrayish)
Has the input's data type, and one axis of length min(nrow, ncol) holding the diagonal elements.

See also

nv_diag() for creating a diagonal matrix, nv_trace()

Examples

# the diagonal of a 3x3 matrix, keeping its data type
x <- nv_array(1:9, shape = c(3, 3))
nv_extract_diag(x)
#> AnvlArray
#>  1
#>  5
#>  9
#> [ CPUi32{3} ]