code: def pad_tensor(x, max_len, mode="zero"):
      """Pad tensors.
  
      Args:
          x (numpy.ndarray): Tensors to be padded.
          max_len (int): Maximum length.
          mode (str): If 'last', pad with the last element, otherwise pad with 0.
  
      Returns:
          numpy.ndarray: Padded tensor.
  
      """
      padding = np.zeros_like(x[0])
      if mode == "last":
          padding = x[-1]
  
      return np.concatenate(
          [
              x,
              np.tile(
                  padding, (max_len - len(x),) + (1,) * np.ndim(x[0])
              ),
          ]
      )
  
file_path: garage/src/garage/np/_functions.py
imports: import warnings
  import numpy
  import scipy.signal
label_desc: Use image node_id 7 for calling a global function with example usage: pad_tensor(x, max_len, mode) and returns: np