gather

paddle.fluid.layers.gather(input, index, overwrite=True)[source]

Gather Layer

Output is obtained by gathering entries of the outer-most dimension of X indexed by index and concatenate them together.

\[Out = X[Index]\]
Given:

X = [[1, 2],
     [3, 4],
     [5, 6]]

Index = [1, 2]

Then:

Out = [[3, 4],
       [5, 6]]
Parameters
  • input (Variable) – The source input tensor with rank>=1. Supported data type is int32, int64, float32, float64 and uint8 (only for CPU), float16 (only for GPU).

  • index (Variable) – The index input tensor with rank=1. Data type is int32 or int64.

  • overwrite (bool, optional) – The mode that updating the grad when has same index. If True, use the overwrite mode to update the grad of the same index, if False, use the accumulate mode to update the grad of the same index. Default value is True.

Returns

The output is a tensor with the same rank as input.

Return type

output (Variable)

Examples

import paddle.fluid as fluid
x = fluid.data(name='x', shape=[-1, 5], dtype='float32')
index = fluid.data(name='index', shape=[-1, 1], dtype='int32')
output = fluid.layers.gather(x, index)