There are multiple ways to provide indices for a sparse tensor. For example, if you have a three-dimensional tensor you can provide indices separated by a comma or a numeric vector of linear indices:

  • c(x[1,1,1], x[1,1,2])

  • x[c(1, 5)]

However for tensors with high dimensions this can be cumbersome to write. Therefore the tensor class also allows you to extract values with indices in matrix or list form, which are more suited for non-interactive coding.

  • x[matrix(c(1,1,1,1,1,2), nrow = 3)]

  • x[list(c(1,1,1), c(1,1,2))]

# S4 method for sptensor,character,missing,ANY
[(x, i, j, ..., drop = FALSE)

# S4 method for sptensor,missing,character,ANY
[(x, i, j, ..., drop = FALSE)

# S4 method for sptensor,character,character,ANY
[(x, i, j, ...,
  drop = FALSE)

# S4 method for sptensor,missing,missing,ANY
[(x, i, j, ..., drop = FALSE)

# S4 method for sptensor,numeric,missing,ANY
[(x, i, j, ..., drop = FALSE)

# S4 method for sptensor,missing,numeric,ANY
[(x, i, j, ..., drop = FALSE)

# S4 method for sptensor,numeric,numeric,ANY
[(x, i, j, ..., drop = FALSE)

# S4 method for sptensor,list,missing,ANY
[(x, i, j, ..., drop = FALSE)

# S4 method for sptensor,matrix,missing,ANY
[(x, i, j, ..., drop = FALSE)

Arguments

x

sptensor object

i

numeric index, vector, list, or matrix

j

numeric index

...

additional numeric indices

drop

whether to drop dimensions