Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

extract-methods

Extract or Replace Subtensors


Description

Extends '[' and '[<-' from the base array class for the Tensor class. Works exactly as it would for the base 'array' class.

Usage

## S4 method for signature 'Tensor'
x[i, j, ..., drop = TRUE]

## S4 replacement method for signature 'Tensor'
x[i, j, ...] <- value

Arguments

x

Tensor to be subset

i, j, ...

indices that specify the extents of the sub-tensor

drop

whether or not to reduce the number of modes to exclude those that have '1' as the mode

value

either vector, matrix, or array that will replace the subtensor

Details

x[i,j,...,drop=TRUE]

Value

an object of class Tensor

Examples

tnsr <- rand_tensor()
tnsr[1,2,3]
tnsr[3,1,]
tnsr[,,5]
tnsr[,,5,drop=FALSE]

tnsr[1,2,3] <- 3; tnsr[1,2,3]
tnsr[3,1,] <- rep(0,5); tnsr[3,1,]
tnsr[,2,] <- matrix(0,nrow=3,ncol=5); tnsr[,2,]

rTensor

Tools for Tensor Analysis and Decomposition

v1.4.8
GPL (>= 2)
Authors
James Li and Jacob Bien and Martin Wells
Initial release
2021-05-14

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.