permute.Rd
Permute the ranks of a tensor, for example to convert between "channels first" and "channels last" representations.
Ranknames are respected for both inputs and return values.
permute(tensor, ..., .dots = NULL)
the tidytensor permute.
ranknames or integers to permute by (quoted or unquoted).
character or integer vector to permute by.
a new tidytensor.
The rank
parameter may be an integer numeric vector (for permuting by index), or character vector (for permuting by rankname).
# shape [20, 26, 26]
t <- as.tidytensor(array(rnorm(20 * 26 * 26), dim = c(20, 26, 26)))
ranknames(t) <- c("sample", "row", "col")
print(t)
#> # Rank 3 tensor, shape: (20, 26, 26), ranknames: sample, row, col
#> | # Rank 2 tensor, shape: (26, 26)
#> | 1.83 -0.721 -1.42 -0.864 -2.15 1.01 ...
#> | 1.13 -0.397 0.998 -1.08 -0.199 0.0444 ...
#> | 1.37 -1.01 0.865 0.0816 0.921 -0.728 ...
#> | -0.6 1.14 -1.59 2.07 2.02 -1.05 ...
#> | 0.0928 -1.11 -3.21 3.37 -2.21 -0.721 ...
#> | -1.66 0.853 0.843 -0.116 -1.68 -0.374 ...
#> | ... ... ... ... ... ... ...
#> | # ...
t2 <- permute(t, col, sample, row)
t2 <- permute(t, 3, 1, 2)
t2 <- permute(t, .dots = c(3, 1, 2))
t2 <- permute(t, .dots = c("col", "sample", "row"))