pad_sequences
used to ensure that all sequences in the list have the same length. By default, this is done by adding 0
at the beginning of each sequence until each sequence has the same length as the longest sequence.
for example
>>> pad_sequences([[1, 2, 3], [3, 4, 5, 6], [7, 8]])
array([[0, 1, 2, 3],
[3, 4, 5, 6],
[0, 0, 7, 8]], dtype=int32)
[3, 4, 5, 6]
- , 0
, [3, 4, 5, 6]
.
, padding='post'
.
, maxlen
. , maxlen
.
>>> pad_sequences([[1, 2, 3], [3, 4, 5, 6], [7, 8]], maxlen=3)
array([[1, 2, 3],
[4, 5, 6],
[0, 7, 8]], dtype=int32)
3.