code: def stack_torch_dict_list(
      dict_list: List[Dict[str, Union[torch.Tensor, np.ndarray]]],
      dim: int = 0,
  ) -> Dict[str, torch.Tensor]:
      """Stack list of dictionaries holding torch tensors as values.
  
      Similar to :func:`~maze.train.utils.train_utils.stack_numpy_dict_list`, but for tensors.
  
      :param dict_list: A list of identical dictionaries to be stacked.
      :param dim: The dimension in which to stack/concat the lists.
      :return: The list entries as a stacked dictionary.
      """
  
      list_dict = defaultdict(list)
      for d in dict_list:
          for k, v in d.items():
              list_dict[k].append(
                  torch.from_numpy(v)
                  if isinstance(v, np.ndarray)
                  else v
              )
  
      stacked_dict = dict()
      for k in list_dict.keys():
          stacked_dict[k] = torch.stack(list_dict[k], dim=dim)
  
      return stacked_dict
  
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 4 for calling a global function with example usage: stack_torch_dict_list(dict_list, dim) and returns: stacked_dict