code: def sample_or_pad(arr, max_size, pad_value=-1):
      """Helper to pad arr along axis 0 to max_size or subsample to max_size."""
      arr_shape = arr.shape
      if arr.size == 0:
          if isinstance(pad_value, list):
              result = (
                  np.ones((max_size, len(pad_value)), dtype=arr.dtype)
                  * pad_value
              )
          else:
              result = np.ones((max_size,), dtype=arr.dtype) * pad_value
      elif arr.shape[0] > max_size:
          if arr.ndim == 1:
              result = np.random.choice(
                  arr, size=max_size, replace=False
              )
          else:
              idx = np.arange(arr.shape[0])
              np.random.shuffle(idx)
              result = arr[idx[:max_size], :]
      else:
          padding = np.ones(
              (max_size - arr.shape[0],) + arr_shape[1:],
              dtype=arr.dtype,
          )
          if isinstance(pad_value, list):
              for i in range(len(pad_value)):
                  padding[..., i] *= pad_value[i]
          else:
              padding *= pad_value
          result = np.concatenate((arr, padding), axis=0)
      # result = np.pad(arr,
      #                 [[0, max_size-arr.shape[0]]] + ([[0, 0]] * (arr.ndim-1)),
      #                 "constant", constant_values=pad_value)
      return result
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import clueweb_text_graph
  import numpy
  import tensorflow
label_desc: Use image node_id 9 for calling a global function with example usage: sample_or_pad(arr, max_size, pad_value) and returns: result