sequence_reshape

paddle.static.nn. sequence_reshape ( input, new_dim ) [source]

Note

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

Only supports Tensor as input. Given new_dim , it will compute new shape according to original length of each sequence, original dimensions and new_dim . Then it will output a new Tensor containing new_dim . Currently it only supports 1-level Tensor. Please make sure that (original length * original dimensions) can be divided by the new_dim with no remainder for each sequence.

input is a Tensor:
    input.lod  = [[0, 2, 6]]
    input.data = [[1,  2], [3,  4],
                  [5,  6], [7,  8],
                  [9, 10], [11, 12]]
    input.shape = [6, 2]

set new_dim = 4
out is a Tensor:
    out.lod  = [[0, 1, 3]]
    out.data = [[1,  2,  3,  4],
                [5,  6,  7,  8],
                [9, 10, 11, 12]]
    out.shape = [3, 4]
Parameters
  • input (Tensor) – 1-level Tensor with shape \([M, K]\) . The data type should be int32, int64, float32 or float64.

  • new_dim (int) – New dimension that the input Tensor is reshaped to.

Returns

Reshaped Tensor according to new dimension. The data type is same as input.

Return type

Tensor

Examples

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

>>> x = paddle.static.data(name='x', shape=[None, 16], dtype='float32', lod_level=1)
>>> x_reshaped = paddle.static.nn.sequence_reshape(input=x, new_dim=4)