gather

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

Warning: API “paddle.fluid.layers.nn.gather” is deprecated since 2.0.0, and will be removed in future versions. Please use “paddle.gather” instead.

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]]
Args:
input (Tensor): The source input tensor with rank>=1. Supported data type is

int32, int64, float32, float64 and uint8 (only for CPU), float16 (only for GPU).

System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/fluid/layers/nn.py:docstring of paddle.fluid.layers.nn.gather, line 32)

Definition list ends without a blank line; unexpected unindent.

index (Tensor): 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.

System Message: ERROR/3 (/usr/local/lib/python3.8/site-packages/paddle/fluid/layers/nn.py:docstring of paddle.fluid.layers.nn.gather, line 34)

Unexpected indentation.

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:

output (Tensor): The output is a tensor with the same rank as input.

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)