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.

tt(x, ...)

Arguments

x

input to convert to a tidytensor.

...

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

Value

a new tidytensor.

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

Examples

# 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)
#> # Rank 3 tensor, shape: (30, 26, 26), ranknames: sample, row, pixel
#> |  # Rank 2 tensor, shape: (26, 26)
#> |      -0.314   -0.27   -2.09   0.586  -0.674   -0.258  ... 
#> |        1.09  -0.495   0.688    1.19   -0.44  -0.0599  ... 
#> |       -1.27   0.244  -0.141   0.585    1.06   -0.796  ... 
#> |       0.285    1.46   -0.53  -0.451  0.0678     1.26  ... 
#> |       0.563   0.226    0.93  -0.473   0.974    0.271  ... 
#> |      -0.291   0.126    1.24  -0.958  -0.119    0.301  ... 
#> |         ...     ...     ...     ...     ...      ...  ... 
#> |  # ...

# 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)
#> # Rank 2 tensor, shape: (26, 26), ranknames: row, pixel
#>       0.54  0.0503   -1.32  -0.588    0.174  -0.522  ... 
#>      0.163  -0.746  -0.777    1.15  -0.0735   -0.99  ... 
#>      0.615  -0.356  0.0945   -1.63   -0.719  -0.434  ... 
#>       1.46  -0.279    1.39   0.393   -0.888    0.81  ... 
#>       1.67   -1.61   0.497  -0.249    -2.22   -1.22  ... 
#>     -0.022  -0.461  -0.258   -1.69   -0.853   0.442  ... 
#>        ...     ...     ...     ...      ...     ...  ... 

# From a vector (representing e.g. 26 pixel values)
v <- rnorm(26)
t <- tt(rnorm(26))
ranknames(t) <- c("pixel")
print(t)
#> # Rank 1 tensor, shape: (26), ranknames: pixel
#>     -1.09  0.542  -0.969  0.00849  -0.0563  -0.194  ...