code: def _stack_arrs(arrs, batch_dim, dtype):
      """
  
      Parameters
      ----------
      arrs
  
      batch_dim
          The batch dimension
      dtype
          torch dtype
  
      Returns
      -------
      stacked_arr
          The resulting stacked array
      """
      if isinstance(arrs[0], np.ndarray):
          stacked_arr = np.stack(arrs, axis=batch_dim)
          return th.as_tensor(stacked_arr, dtype=dtype)
      elif isinstance(arrs[0], th.Tensor):
          ret = th.stack(arrs, dim=batch_dim)
          if dtype is None:
              dtype = ret.dtype
          if ret.dtype != dtype:
              return ret.type(dtype)
          else:
              return ret
      else:
          stacked_arr = np.stack(
              [np.array(arr) for arr in arrs], axis=batch_dim
          )
          return th.as_tensor(stacked_arr, dtype=dtype)
  
imports: import math
  from typing import AnyStr
  from typing import Callable
  from typing import Dict
  from typing import List
  from typing import NamedTuple
  from typing import Tuple
  from typing import Union
  import numpy
  import torch
  from ..utils import to_torch_dtype
label_desc: Use image node_id 2 for calling a global function with example usage: _stack_arrs(arrs, batch_dim, dtype) and returns: th, th, ret, ret