tt: Convert a vector, matrix, or array to a tidytensor type.

Description Usage Arguments Details Value See Also Examples

Description

tt() is a convenience shorthand for as.tidytensor(). Given a vector, matrix, or array, returns a tidytensor. If given a vector, converts to a 1-d array supporting dim(), matrices are left as matrices, and in all cases the class 'tidytensor' is added.

Usage

1
tt(x, ...)

Arguments

x

input to convert to a tidytensor.

...

additional arguments to be passed to or from methods (ignored).

Details

Matrices are synonymous with 2-d arrays, so these are left as is. Vectors are converted to 1-d arrays so that they can support dim().

Value

a new tidytensor.

See Also

print.tidytensor, ranknames.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# From an array (representing e.g. 30 26x26 images (30 sets of 26 rows of 26 pixels))
a <- array(rnorm(30 * 26 * 26), dim = c(30, 26, 26))
t <- tt(a)
ranknames(t) <- c("sample", "row", "pixel")
print(t)

# From a matrix (representing e.g. a 26x26 image (26 rows of 26 pixels)) using %>%
library(magrittr)
t <- matrix(rnorm(26 * 26), nrow = 26, ncol = 26) %>% tt()
ranknames(t) <- c("row", "pixel")
print(t)

# From a vector (representing e.g. 26 pixel values)
v <- rnorm(26)
t <- tt(rnorm(26))
ranknames(t) <- c("pixel")
print(t)

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