oneflow.tensor_scatter_nd_update

oneflow.tensor_scatter_nd_update(tensor, indices, updates)

This operation creates a new tensor by applying sparse updates to the input tensor. This is similar to an index assignment.

This operator is very similar to scatter_nd(), except that the updates are scattered onto an existing tensor (as opposed to a zero-tensor).

Parameters
  • tensor – The tensor will be scattered.

  • indices – The indices of update. Its type should be flow.int.

  • update – The update Tensor.

For example:

>>> import oneflow as flow
>>> tensor = flow.arange(8)
>>> indices = flow.tensor([[1], [3], [5]])
>>> updates = flow.tensor([-1, -2, -3])
>>> flow.tensor_scatter_nd_update(tensor, indices, updates)
tensor([ 0, -1,  2, -2,  4, -3,  6,  7], dtype=oneflow.int64)