# NOT RUN {
x <- rray(
1:6,
c(3, 2),
dim_names = list(rows = c("r1", "r2", "r3"), cols = c("c1", "c2"))
)
# A standard transpose
rray_transpose(x)
# Identical to
rray_transpose(x, rev(1:2))
x_3d <- rray_broadcast(x, c(3, 2, 2))
# transpose here is like setting
# `permutation = c(3, 2, 1)`
# so the result should change _shape_ like:
# (3, 2, 2) -> (2, 2, 3)
rray_transpose(x_3d)
# This transposes the "inner" matrices
# (flips the first and second dimension)
# and leaves the 3rd dimension alone
rray_transpose(x_3d, c(2, 1, 3))
# ---------------------------------------------------------------------------
# Difference from base R
# Coerces 1:5 into a 2D matrix, then transposes
t(1:5)
# Leaves it as a 1D array and does nothing
rray_transpose(1:5)
# t.vctrs_rray() has the same behavior
# as base R
t(rray(1:5))
# }
Run the code above in your browser using DataLab