code: def _mask_sequences_py(
      sequence, sequence_length, dtype=None, time_major=False
  ):
      """Masks out sequence entries that are beyond the respective sequence
      lengths. Masks along the time dimension.
  
      This is the numpy version of :func:`texar.tf.utils.mask_sequences`.
  
      Args:
          sequence: An python array of sequence values.
  
              If `time_major=False` (default), this must be an array of shape:
                  `[batch_size, max_time, ...]`
  
              If `time_major=True`, this must be a Tensor of shape:
                  `[max_time, batch_size, ...].`
          sequence_length: An array of shape `[batch_size]`. Time steps beyond
              the respective sequence lengths will be made zero.
          dtype (dtype): Type of :attr:`sequence`. If `None`, infer from
              :attr:`sequence` automatically.
          time_major (bool): The shape format of the inputs. If `True`,
              :attr:`sequence` must have shape
              `[max_time, batch_size, ...]`.
              If `False` (default), :attr:`sequence` must have
              shape `[batch_size, max_time, ...]`.
  
      Returns:
          The masked sequence, i.e., an array of the same shape as
          :attr:`sequence` but with masked-out entries (set to zero).
      """
      sequence = np.array(sequence)
      sequence_length = np.array(sequence_length)
  
      rank = sequence.ndim
      if rank < 2:
          raise ValueError("`sequence` must be 2D or higher order.")
      batch_size = sequence.shape[0]
      max_time = sequence.shape[1]
      dtype = dtype or sequence.dtype
  
      if time_major:
          sequence = np.transpose(sequence, axes=[1, 0, 2])
  
      steps = np.tile(np.arange(max_time), [batch_size, 1])
      mask = np.asarray(steps < sequence_length[:, None], dtype=dtype)
      for _ in range(2, rank):
          mask = np.expand_dims(mask, -1)
  
      sequence = sequence * mask
  
      if time_major:
          sequence = np.transpose(sequence, axes=[1, 0, 2])
  
      return sequence
  
file_path: texar/texar/tf/utils/shapes.py
imports: import numpy
  import tensorflow
  from tensorflow.python.util import nest
  from tensorflow.python.ops import rnn
  from tensorflow.python.framework import ops
label_desc: Use image node_id 6 for calling a global function with example usage: _mask_sequences_py(sequence, sequence_length, dtype, time_major) and returns: sequence