code: def stack_torch_array_list(
      array_list: List[Union[np.ndarray, torch.Tensor]],
      expand: bool = False,
      dim: int = 0,
  ) -> torch.Tensor:
      """Batch together a list of arrays (either torch or numpy) after converting them to torch. That is ether stack them
          if the batch dimension does not exists, otherwise concatenate them in the batch dimension (2)
  
      :param array_list: A list of arrays (either torch or numpy)
          :param expand: If True the values are expended by one dimension at dimension :param dim.
      :param dim: The dimension in which to stack/concat the lists.
  
      :return: the batched input
      """
      list_array = []
      for idx, array in enumerate(array_list):
          list_array.append(
              torch.from_numpy(array)
              if isinstance(array, np.ndarray)
              else array
          )
  
      if expand:
          stacked_list = torch.stack(list_array, dim=dim)
      else:
          stacked_list = torch.cat(list_array, dim=dim)
  
      return stacked_list
  
file_path: maze/maze/train/utils/train_utils.py
imports: from collections import defaultdict
  from typing import List, Dict, Iterable, Union
  import numpy
  import torch
  from maze.core.env.structured_env import ActorID
label_desc: Use image node_id 5 for calling a global function with example usage: stack_torch_array_list(array_list, expand, dim) and returns: stacked_list