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

shuffle(t, seed = NULL)

Arguments

t

the tidytensor to apply over.

seed

random seed to be used for shuffling.

Value

a tidytensor of the same shape.

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.

See also

Examples

# 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)
#> # Rank 3 tensor, shape: (100, 26, 26), ranknames: sample, row, col
#> |  # Rank 2 tensor, shape: (26, 26)
#> |      -0.0725   0.463    -1.14   0.191   0.566   0.377  ... 
#> |      -0.0337   -2.17   -0.384     1.4   0.985   -0.28  ... 
#> |      -0.0627   0.826     1.97   -1.73    1.04   0.224  ... 
#> |          1.2  -0.931     1.13    1.58  -0.904  -0.252  ... 
#> |          1.1   0.597     1.05   -1.93  -0.275   0.629  ... 
#> |        0.527   0.662  -0.0705  -0.506   0.891   0.177  ... 
#> |          ...     ...      ...     ...     ...     ...  ... 
#> |  # ...

t <- shuffle(t, seed = 42)