code: def convert_to_numpy(
      stats: Any,
      cast: Union[np.dtype, None],
      in_place: Union[bool, str],
  ):
      """Convert torch to np
  
      :param stats: Any (possibly nested) struct, the values in which will be
          converted and returned as a new struct with all leaves converted
          to torch tensors.
      :param cast: if the element should also be casted to a specific type
      :param in_place: specify if the operation should be done in_palce, can be bool or 'try'
  
      :return: A new struct with the same structure as `stats`, but with all
              values converted to torch Tensor types. can be bool or 'try'
      """
  
      def mapping(item):
          """Define mapping"""
          if isinstance(item, torch.Tensor):
              item = item.cpu().numpy()
          # Cast the tensor to the desired format
          return item if cast is None else item.astype(cast)
  
      assert in_place in [True, False, "try"]
      if in_place == "try":
          return map_nested_structure(stats, mapping, in_place, 1)
      else:
          return map_nested_structure(stats, mapping, in_place)
  
file_path: maze/maze/perception/perception_utils.py
imports: import collections
  from collections import defaultdict
  from typing import Union, Dict, Any, Callable, Sequence, Iterable
  import gym
  import numpy
  import torch
  from gym import spaces
  from maze.core.env.structured_env import StepKeyType
  from maze.core.utils.structured_env_utils import flat_structured_space
label_desc: Use image node_id 5 for calling a global function with example usage: convert_to_numpy(stats, cast, in_place) and returns: unknown, map_nested_structure, map_nested_structure