sequence_reverse

paddle.static.nn. sequence_reverse ( x, name=None ) [source]

Note

Only receives Tensor as input. If your input is Tensor, please use reverse Op.(static.nn.** flip ).

Only supports Tensor as input. It will reverse each sequence for input Tensor. Currently it only supports 1-level Tensor. This operator is very useful when building a reverse RNN network.

input(x) is a Tensor:
    x.lod  = [[0, 2, 5]]
    x.data = [[1,  2,  3,  4],
              [5,  6,  7,  8],
              [9, 10, 11, 12],
              [13,14, 15, 16],
              [17,18, 19, 20]]
    x.shape = [5, 4]

output Tensor with same shape and LoD info:
    out.lod  = [[0, 2, 5]]
    out.data = [[5,  6,  7,  8],
                [1,  2,  3,  4],
                [17,18, 19, 20],
                [13,14, 15, 16],
                [9, 10, 11, 12]]
    out.shape = [5, 4]
Parameters
  • x (Tensor) – Tensor with 1-level LoD info. Currently it only supports 1-level Tensor. The data type should be float32, float64, int8, int32 or int64.

  • 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 .

Returns

Tensor reversed from input. The data type is same with input.

Return type

Tensor

Examples

>>> import paddle
>>> paddle.enable_static()

>>> x = paddle.static.data(name='x', shape=[None, 10], dtype='float32', lod_level=1)
>>> x_reversed = paddle.static.nn.sequence_reverse(x)