shuffle: Shuffle a tidytensor in the first rank.

Description Usage Arguments Details Value See Also Examples

View source: R/shuffle.R

Description

Shuffle's the entries in the first rank of a tensor. For example, if x has shape (3, 5, 5), it may be indexed as x[c(2, 3, 1), , ]. It's possible to set a custom seed for repeatable shuffling (amongst tensors with the same size in the first rank).

Usage

1
shuffle(t, seed = NULL)

Arguments

t

the tidytensor to apply over.

seed

random seed to be used for shuffling.

Details

Since tidytensor consider tensors as representing hierarchical "set of" relationships, shuffling in any rank other than the first would permute lower entities across set boundaries in higher ranks. For example, in a set of color images of shape (500, 28, 28, 3), shuffling the last rank would re-order the channels, but identically for all the images. See tt_apply for applying functions (such as shuffle) over lower ranks of a tensor.

Value

a tidytensor of the same shape.

See Also

tt_apply, permute

Examples

1
2
3
4
5
6
# shape [100, 26, 26]
t <- as.tidytensor(array(rnorm(100 * 26 * 26), dim = c(100, 26, 26)))
ranknames(t) <- c("sample", "row", "col")
print(t)

t <- shuffle(t, seed = 42)

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