scatter_nd

paddle.fluid.layers.scatter_nd(index, updates, shape, name=None)[source]

Scatter_nd Layer

Output is obtained by scattering the updates in a new tensor according to index . This op is similar to scatter_nd_add, except the tensor of shape is zero-initialized. Correspondingly, scatter_nd(index, updates, shape) is equal to scatter_nd_add(fluid.layers.zeros(shape, updates.dtype), index, updates) . If index has repeated elements, then the corresponding updates are accumulated. Because of the numerical approximation issues, the different order of repeated elements in index may cause different results. The specific calculation method can be seen scatter_nd_add . This op is the inverse of the gather_nd op.

Parameters
  • index (Variable) – The index input with rank > 1 and index.shape[-1] <= len(shape). Its dtype should be int32 or int64 as it is used as indexes.

  • updates (Variable) – The updated value of scatter_nd op. Its dtype should be int32, int64, float32, float64. It must have the shape index.shape[:-1] + shape[index.shape[-1]:]

  • shape (tuple|list) – Shape of output tensor.

  • name (str|None) – The output variable name. If set None, the layer will be named automatically.

Returns

The output is a tensor with the same type as updates .

Return type

output (Variable)

Examples

import paddle.fluid as fluid

index = fluid.data(name='index', shape=[3, 2], dtype='int64')
updates = fluid.data(name='update', shape=[3, 9, 10], dtype='float32')
shape = [3, 5, 9, 10]

output = fluid.layers.scatter_nd(index, updates, shape)