class_docstr: A dictionary of :class:`Space` instances.
  
  Elements of this space are (ordered) dictionaries of elements from the constituent spaces.
  
  Example usage:
  
      >>> from gym.spaces import Dict, Discrete
      >>> observation_space = Dict({"position": Discrete(2), "velocity": Discrete(3)})
      >>> observation_space.sample()
      OrderedDict([('position', 1), ('velocity', 2)])
  
  Example usage [nested]::
  
      >>> from gym.spaces import Box, Dict, Discrete, MultiBinary, MultiDiscrete
      >>> Dict(
      ...     {
      ...         "ext_controller": MultiDiscrete([5, 2, 2]),
      ...         "inner_state": Dict(
      ...             {
      ...                 "charge": Discrete(100),
      ...                 "system_checks": MultiBinary(10),
      ...                 "job_status": Dict(
      ...                     {
      ...                         "task": Discrete(5),
      ...                         "progress": Box(low=0, high=100, shape=()),
      ...                     }
      ...                 ),
      ...             }
      ...         ),
      ...     }
      ... )
  
  It can be convenient to use :class:`Dict` spaces if you want to make complex observations or actions more human-readable.
  Usually, it will not be possible to use elements of this space directly in learning code. However, you can easily
  convert `Dict` observations to flat arrays by using a :class:`gym.wrappers.FlattenObservation` wrapper. Similar wrappers can be
  implemented to deal with :class:`Dict` actions.
docstr: Generates a single random sample from this space.
  
  The sample is an ordered dictionary of independent samples from the constituent spaces.
  
  Args:
      mask: An optional mask for each of the subspaces, expects the same keys as the space
  
  Returns:
      A dictionary with the same key and sampled values from :attr:`self.spaces`
docstr_tok: ["Generates","a","single","random","sample","from","this","space",".","The","sample","is","an","ordered","dictionary","of","independent","samples","from","the","constituent","spaces",".","Args",":","mask",":","An","optional","mask","for","each","of","the","subspaces",",","expects","the","same","keys","as","the","space","Returns",":","A","dictionary","with","the","same","key","and","sampled","values","from",":","attr",":","`","self.spaces","`"]
code: def sample(self, mask: Optional[TypingDict[str, Any]] = None) -> dict:
      """Generates a single random sample from this space.
  
      The sample is an ordered dictionary of independent samples from the constituent spaces.
  
      Args:
          mask: An optional mask for each of the subspaces, expects the same keys as the space
  
      Returns:
          A dictionary with the same key and sampled values from :attr:`self.spaces`
      """
      if mask is not None:
          assert isinstance(
              mask, dict
          ), f"Expects mask to be a dict, actual type: {type(mask)}"
          assert (
              mask.keys() == self.spaces.keys()
          ), f"Expect mask keys to be same as space keys, mask keys: {mask.keys()}, space keys: {self.spaces.keys()}"
          return OrderedDict(
              [
                  (k, space.sample(mask[k]))
                  for k, space in self.spaces.items()
              ]
          )
  
      return OrderedDict(
          [(k, space.sample()) for k, space in self.spaces.items()]
      )
  
imports: from collections import OrderedDict
  from collections.abc import Mapping, Sequence
  from typing import Any
  from typing import Dict
  from typing import List, Optional
  from typing import Sequence
  from typing import Tuple, Union
  import numpy
  from gym.spaces.space import Space
label_desc: Use image node_id 4 for calling the Dict obj's underlying member method code with example usage: obj.sample(mask) and returns: OrderedDict, OrderedDict