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))]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ## S4 method for signature 'sptensor,character,missing,ANY'
x[i, j, ..., drop = FALSE]
## S4 method for signature 'sptensor,missing,character,ANY'
x[i, j, ..., drop = FALSE]
## S4 method for signature 'sptensor,character,character,ANY'
x[i, j, ...,
drop = FALSE]
## S4 method for signature 'sptensor,missing,missing,ANY'
x[i, j, ..., drop = FALSE]
## S4 method for signature 'sptensor,numeric,missing,ANY'
x[i, j, ..., drop = FALSE]
## S4 method for signature 'sptensor,missing,numeric,ANY'
x[i, j, ..., drop = FALSE]
## S4 method for signature 'sptensor,numeric,numeric,ANY'
x[i, j, ..., drop = FALSE]
## S4 method for signature 'sptensor,list,missing,ANY'
x[i, j, ..., drop = FALSE]
## S4 method for signature 'sptensor,matrix,missing,ANY'
x[i, j, ..., drop = FALSE]
|
x |
sptensor object |
i |
numeric index, vector, list, or matrix |
j |
numeric index |
... |
additional numeric indices |
drop |
whether to drop dimensions |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.