Skip to contents

Extracts a subset from a tensor. You can also use the [ operator. Supports R-style indexing including scalar indices (which drop dimensions), ranges (a:b), and list() for selecting multiple elements along a dimension.

Usage

# S3 method for class 'AnvilBox'
x[...]

# S3 method for class 'AnvilTensor'
x[...]

nv_subset(x, ...)

Arguments

x

(tensorish)
Tensor to subset.

...


Subset specifications, one per dimension. Omitted trailing dimensions select all elements. See vignette("subsetting") for details.

Value

tensorish

See also

nv_subset_assign() for updating subsets, vignette("subsetting") for a comprehensive guide.

Examples

jit_eval({
  x <- nv_tensor(matrix(1:12, nrow = 3))
  # Select row 2
  x[2, ]
})
#> AnvilTensor
#>   2
#>   5
#>   8
#>  11
#> [ CPUi32{4} ] 

jit_eval({
  x <- nv_tensor(matrix(1:12, nrow = 3))
  # Select rows 1 to 2, all columns
  x[1:2, ]
})
#> AnvilTensor
#>   1  4  7 10
#>   2  5  8 11
#> [ CPUi32{2,4} ]