qml.math.scatter_element_add

scatter_element_add(tensor, index, value)[source]

Adds a scalar value to a specific index of a tensor.

This is a pure equivalent of tensor[index] += value.

Parameters
  • tensor (tensor_like) – the input tensor to be updated

  • index (tuple[int]) – the index of the input tensor to update

  • value (scalar) – the scalar value to add to the tensor element

Returns

the output tensor

Return type

tensor_like

Example

>>> x = torch.ones((2, 3))
>>> qml.math.scatter_element_add(x, [1, 2], 3)
tensor([[1., 1., 1.],
        [1., 1., 4.]])