code: def pad_sequence(sequences, batch_first=False, padding_value=0.0):
      """Pad a list of variable-length Variables.
  
      This method stacks a list of variable-length :obj:`nnabla.Variable` s with the padding_value.
  
      :math:`T_i` is the length of the :math:`i`-th Variable in the sequences.
      :math:`B` is the batch size equal to the length of the sequences.
      :math:`T` is the max of :math:`T_i` for all :math:`i`.
      :math:`*` is the remaining dimensions including none.
  
      .. note::
        This function **must** be used the dynamic computation mode.
  
      Example:
  
      .. code-block:: python
  
        import numpy as np
        import nnabla as nn
        import nnabla.functions as F
        import nnabla.utils.rnn as rnn_utils
  
        nn.set_auto_forward(True)
  
        l2v = lambda ldata: nn.Variable.from_numpy_array(np.asarray(ldata))
        a = l2v([1, 1, 1, 1])
        b = l2v([2, 2, 2])
        c = l2v([2, 2, 2])
        d = l2v([3, 3])
        e = l2v([3, 3])
        sequences = [a, b, c, d, e]
  
        padded_sequence = rnn_utils.pad_sequence(sequences)
        print(padded_sequence.d)
  
      Args:
        sequences (list of :obj:`nnabla.Variable`): Sequence of the variable of (:math:`T_i`, :math:`*`) shape.
        batch_first (bool): If False, output is of (:math:`T`, :math:`B`, :math:`*`) shape,
                            otherwise (:math:`B`, :math:`T`, :math:`*`).
        padding_value (float): Padding value.
  
      Returns:
        :obj:`nnabla.Variable` of (:math:`T`, :math:`B`, :math:`*`) or (:math:`B`, :math:`T`, :math:`*`) shape
      """
  
      B = len(sequences)
      T = max([e.shape[0] for e in sequences])
      shape0 = (B, T) if batch_first else (T, B)
      shape1 = sequences[0].shape[1:]
  
      padded_sequence = F.constant(padding_value, shape0 + shape1)
      for b, s in enumerate(sequences):
          l = s.shape[0]
          if batch_first:
              padded_sequence[b, :l, ...] = s
          else:
              padded_sequence[:l, b, ...] = s
      return padded_sequence
  
file_path: nnabla/python/src/nnabla/utils/rnn.py
imports: import nnabla
  import nnabla.functions
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: pad_sequence(sequences, batch_first, padding_value) and returns: padded_sequence