Permutes the axes of an array, like base::aperm(). nv_transpose() is
another spelling of the same function. You can also use aperm(), or
t() for matrices.
Arguments
- x
(
arrayish)
One input. Can be any data type. An R value materializes at its default data type.- perm
(
integer()|NULL)
New ordering of axes. IfNULL(default), reverses the axes. Negative values count from the end, i.e.-1refers to the last axis.- a
(
arrayish)
The array whose axes to permute.- ...
No additional arguments.
Value
(arrayish)
Has x's data type and shape shape(x)[perm], or rev(shape(x))
when perm is NULL.
The t() generic
t() requires a matrix, whereas base::t() also transposes a vector (into
a one-row matrix). Like base::t(), it rejects a higher-rank array; use
aperm() to reverse its axes.
The aperm() generic
aperm() permutes the axes exactly as nv_aperm() does; like
base::aperm(), perm = NULL reverses them.
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)
nv_aperm(x)
#> AnvlArray
#> 1 2
#> 3 4
#> 5 6
#> [ CPUi32{3,2} ]
t(x)
#> AnvlArray
#> 1 2
#> 3 4
#> 5 6
#> [ CPUi32{3,2} ]
nv_aperm(nv_array(1:24, shape = c(2, 3, 4)), c(3, 1, 2))
#> AnvlArray
#> (1,.,.) =
#> 1 3 5
#> 2 4 6
#>
#> (2,.,.) =
#> 7 9 11
#> 8 10 12
#>
#> (3,.,.) =
#> 13 15 17
#> 14 16 18
#>
#> (4,.,.) =
#> 19 21 23
#> 20 22 24
#> [ CPUi32{4,2,3} ]