# tensorplay.nn.utils.rnn.pack_sequence

Source: https://www.tensorplay.cn/docs/generated/tensorplay.nn.utils.rnn.pack_sequence.html

# tensorplay.nn.utils.rnn.pack_sequence

tensorplay.nn.utils.rnn.pack_sequence(sequences, enforce_sorted: [bool](https://docs.python.org/3/library/functions.html#bool) = True) &#x2192; [PackedSequence](tensorplay.nn.utils.rnn.PackedSequence.html#tensorplay.nn.utils.rnn.PackedSequence)[[source]](../_modules/tensorplay/nn/utils/rnn.html#pack_sequence)

Packs a list of variable length Tensors.

Consecutive call of the next functions: pad_sequence, pack_padded_sequence.

sequences should be a list of Tensors of size L x *, where L is
the length of a sequence and * is any number of trailing dimensions,
including 0.

For unsorted sequences, use enforce_sorted = False. If enforce_sorted is
True, the sequences should be sorted in the order of decreasing length.
enforce_sorted = True is only necessary for ONNX export.

Example

```
>>> from tensorplay.nn.utils.rnn import pack_sequence
>>> a = tp.tensor([1, 2, 3])
>>> b = tp.tensor([4, 5])
>>> c = tp.tensor([6])
>>> pack_sequence([a, b, c])
PackedSequence(data=tensor([1, 4, 6, 2, 5, 3]), batch_sizes=tensor([3, 2, 1]), sorted_indices=None, unsorted_indices=None)
```

Parameters:

- sequences ([list](https://docs.python.org/3/library/stdtypes.html#list) [ Tensor ] ) – A list of sequences of decreasing length.

- enforce_sorted ([bool](https://docs.python.org/3/library/functions.html#bool) , optional ) – if True , checks that the input contains sequences sorted by length in a decreasing order. If False , this condition is not checked. Default: True .

Returns:

a [PackedSequence](tensorplay.nn.utils.rnn.PackedSequence.html#tensorplay.nn.utils.rnn.PackedSequence) object
