code: def pad_sequence(sequences, batch_first):
      # sequences: list of nparray
      # sequences[i]: (T_i, D_1, ..., D_M)
      Ds = (
          () if len(sequences[0].shape) == 1 else sequences[0].shape[1:]
      )
      B = len(sequences)
      T = max([seq.shape[0] for seq in sequences])
      data = (
          np.zeros((B, T) + Ds)
          if batch_first
          else np.zeros((T, B) + Ds)
      )
      for b, seq in enumerate(sequences):
          l = seq.shape[0]
          if batch_first:
              data[b, :l] = seq
          else:
              data[:l, b] = seq
      return data
  
imports: from __future__ import division
  from six.moves import range
  import itertools
  import numpy
label_desc: Use image node_id 20 for calling a global function with example usage: pad_sequence(sequences, batch_first) and returns: data