gather( x, index, axis=None, name=None )
Output is obtained by gathering entries of
indexand concatenate them together.
Given: x = [[1, 2], [3, 4], [5, 6]] index = [1, 2] axis= Then: out = [[3, 4], [5, 6]]
x (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).
index (Tensor) – The index input tensor with rank=1. Data type is int32 or int64.
axis (Tensor|int, optional) – The axis of input to be gathered, it’s can be int or a Tensor with data type is int32 or int64. The default value is None, if None, the
name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name .
The output is a tensor with the same rank as
- Return type
import paddle input = paddle.to_tensor([[1,2],[3,4],[5,6]]) index = paddle.to_tensor([0,1]) output = paddle.gather(input, index, axis=0) # expected output: [[1,2],[3,4]]