code: def zero_pad_truncate(
      batch: Sequence[
          Sequence[
              Union[
                  int,
                  float,
                  np.integer,
                  np.floating,
                  Sequence[Union[int, float, np.integer, np.floating]],
              ]
          ]
      ],
      max_len: int,
      pad: str = "post",
      trunc: str = "post",
      dtype: Optional[Union[type, str]] = None,
  ) -> np.ndarray:
      """
  
      Args:
          batch: assumes a batch of lists of word indexes or their vector representations
          max_len: resulting length of every batch item
          pad: how to pad shorter batch items: can be ``'post'`` or ``'pre'``
          trunc: how to truncate a batch item: can be ``'post'`` or ``'pre'``
          dtype: overrides dtype for the resulting ``ndarray`` if specified,
           otherwise ``np.int32`` is used for 2-d arrays and ``np.float32`` — for 3-d arrays
  
      Returns:
          a 2-d array of size ``(len(batch), max_len)`` or a 3-d array of size ``(len(batch), max_len, len(batch[0][0]))``
      """
      if isinstance(
          batch[0][0], Collection
      ):  # ndarray behaves like a Sequence without actually being one
          size = (len(batch), max_len, len(batch[0][0]))
          dtype = dtype or np.float32
      else:
          size = (len(batch), max_len)
          dtype = dtype or np.int32
  
      padded_batch = np.zeros(size, dtype=dtype)
      for i, batch_item in enumerate(batch):
          if len(batch_item) > max_len:  # trunc
              padded_batch[i] = batch_item[
                  slice(max_len)
                  if trunc == "post"
                  else slice(-max_len, None)
              ]
          else:  # pad
              padded_batch[
                  i,
                  slice(len(batch_item))
                  if pad == "post"
                  else slice(-len(batch_item), None),
              ] = batch_item
  
      return np.asarray(padded_batch)
  
imports: import collections
  import gzip
  import os
  import secrets
  import shutil
  import tarfile
  import zipfile
  from hashlib import md5
  from itertools import chain
  from logging import getLogger
  from pathlib import Path
  from typing import Any, Generator, Iterable, List, Mapping, Optional, Sequence, Sized, Union, Collection
  from urllib.parse import urlencode, parse_qs, urlsplit, urlunsplit, urlparse
  import numpy
  import requests
  from tqdm import tqdm
label_desc: Use image node_id 17 for calling a global function with example usage: zero_pad_truncate(batch, max_len, pad, trunc, dtype) and returns: np