code: def _unflatten_tuple(
      space: Tuple, x: Union[np.ndarray, tuple]
  ) -> tuple:
      if space.is_np_flattenable:
          assert isinstance(
              x, np.ndarray
          ), f"{space} is numpy-flattenable. Thus, you should only unflatten numpy arrays for this space. Got a {type(x)}"
          dims = np.asarray(
              [flatdim(s) for s in space.spaces], dtype=np.int_
          )
          list_flattened = np.split(x, np.cumsum(dims[:-1]))
          return tuple(
              unflatten(s, flattened)
              for flattened, s in zip(list_flattened, space.spaces)
          )
      assert isinstance(
          x, tuple
      ), f"{space} is not numpy-flattenable. Thus, you should only unflatten tuples for this space. Got a {type(x)}"
      return tuple(
          unflatten(s, flattened)
          for flattened, s in zip(x, space.spaces)
      )
  
imports: import operator
  from collections import OrderedDict
  from functools import reduce, singledispatch
  from typing import Dict
  from typing import TypeVar, Union, cast
  import numpy
  from gym.spaces import Box, Dict, Discrete, Graph, GraphInstance, MultiBinary, MultiDiscrete, Sequence, Space, Text, Tuple
label_desc: Use image node_id 22 for calling a global function with example usage: _unflatten_tuple(space, x) and returns: tuple, tuple