Skip to contents

Updates elements of a tensor at specified positions, returning a new tensor. You can also use the [<- operator.

Usage

# S3 method for class 'AnvilBox'
x[...] <- value

# S3 method for class 'AnvilTensor'
x[...] <- value

nv_subset_assign(x, ..., value)

Arguments

x

(tensorish)
Tensor to update.

...


Subset specifications, one per dimension. See vignette("subsetting") for details.

value

(tensorish)
Replacement values. Scalars are broadcast to the subset shape. Non-scalar values must match the subset shape.

Value

tensorish
A new tensor with the same shape as x and the subset replaced.

See also

nv_subset(), vignette("subsetting") for a comprehensive guide.

Examples

jit_eval({
  x <- nv_tensor(matrix(1:12, nrow = 3))
  # Set row 1 to zeros
  x[1, ] <- 0L
  x
})
#> AnvilTensor
#>   0  0  0  0
#>   2  5  8 11
#>   3  6  9 12
#> [ CPUi32{3,4} ]