code: def trim_or_pad_to_target_length(
      data_1d_or_2d: np.ndarray, target_length: int
  ) -> np.ndarray:
      assert len(data_1d_or_2d.shape) in {1, 2}
      delta = data_1d_or_2d.shape[0] - target_length
      if delta >= 0:  # trim if being longer
          data_1d_or_2d = data_1d_or_2d[:target_length]
      else:  # pad if being shorter
          if len(data_1d_or_2d.shape) == 1:
              data_1d_or_2d = np.concatenate(
                  [data_1d_or_2d, np.zeros(-delta)], axis=0
              )
          else:
              data_1d_or_2d = np.concatenate(
                  [
                      data_1d_or_2d,
                      np.zeros((-delta, data_1d_or_2d.shape[1])),
                  ],
                  axis=0,
              )
      return data_1d_or_2d
  
imports: import io
  import os
  from pathlib import Path
  from typing import Optional, List, Dict
  import zipfile
  import tempfile
  from dataclasses import dataclass
  from itertools import groupby
  import torch
  import torch.nn.functional
  import numpy
  from tqdm import tqdm
  from examples.speech_to_text.data_utils import load_tsv_to_dicts
  from fairseq.data.audio.audio_utils import TTSSpectrogram, TTSMelScale, parse_path, read_from_stored_zip, is_npy_data
label_desc: Use image node_id 1 for calling a global function with example usage: trim_or_pad_to_target_length(data_1d_or_2d, target_length) and returns: data_1d_or_2d