oneflow.scatter_nd

oneflow.scatter_nd(index, update, shape)

This operator inserts the elements in update according to the index and create a new Tensor.

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

  • update – The update Tensor.

  • shape (Sequence[int]) – The constant tensor shape, the constant tensor elements are all zero.

For example:

>>> import oneflow as flow
>>> import numpy as np
>>> index = flow.tensor(np.array([[1], [6], [4]]), dtype=flow.int)
>>> update = flow.tensor(np.array([10.2, 5.1, 12.7]), dtype=flow.float)
>>> out = flow.scatter_nd(index, update, [8])
>>> out
tensor([ 0.0000, 10.2000,  0.0000,  0.0000, 12.7000,  0.0000,  5.1000,  0.0000],
       dtype=oneflow.float32)