Skip to contents

Permutes the axes of an array. You can also use t() for matrices.

Usage

nv_transpose(x, permutation = NULL)

Arguments

x

(arrayish)
One input. Can be any data type. An R value materializes at its default data type.

permutation

(integer() | NULL)
New ordering of axes. If NULL (default), reverses the axes. Negative values count from the end, i.e. -1 refers to the last axis.

Value

(arrayish)
Has x's data type and shape shape(x)[permutation], or rev(shape(x)) when permutation is NULL.

The t() generic

t() requires a matrix, whereas base::t() also transposes a vector (into a one-row matrix) and reverses the axes of a higher-rank array.

See also

prim_transpose() for the underlying primitive.

Examples

# the 2x3 becomes a 3x2, keeping its data type
x <- nv_matrix(1:6, nrow = 2)
t(x)
#> AnvlArray
#>  1 2
#>  3 4
#>  5 6
#> [ CPUi32{3,2} ]