permute: Permute the ranks of a tensor

Description Usage Arguments Details Value Examples

View source: R/permute.tidytensor.R

Description

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.

Usage

1
permute(tensor, ..., .dots = NULL)

Arguments

tensor

the tidytensor permute.

...

ranknames or integers to permute by (quoted or unquoted).

.dots

character or integer vector to permute by.

Details

The rank parameter may be an integer numeric vector (for permuting by index), or character vector (for permuting by rankname).

Value

a new tidytensor.

Examples

1
2
3
4
5
6
7
8
9
# 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)

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"))

oneilsh/tidytensor documentation built on Oct. 11, 2021, 11:43 p.m.