class_docstr: Superclass that is used to define observation and action spaces.
  
  Spaces are crucially used in Gym to define the format of valid actions and observations.
  They serve various purposes:
  
  * They clearly define how to interact with environments, i.e. they specify what actions need to look like
    and what observations will look like
  * They allow us to work with highly structured data (e.g. in the form of elements of :class:`Dict` spaces)
    and painlessly transform them into flat arrays that can be used in learning code
  * They provide a method to sample random elements. This is especially useful for exploration and debugging.
  
  Different spaces can be combined hierarchically via container spaces (:class:`Tuple` and :class:`Dict`) to build a
  more expressive space
  
  Warning:
      Custom observation & action spaces can inherit from the ``Space``
      class. However, most use-cases should be covered by the existing space
      classes (e.g. :class:`Box`, :class:`Discrete`, etc...), and container classes (:class`Tuple` &
      :class:`Dict`). Note that parametrized probability distributions (through the
      :meth:`Space.sample()` method), and batching functions (in :class:`gym.vector.VectorEnv`), are
      only well-defined for instances of spaces provided in gym by default.
      Moreover, some implementations of Reinforcement Learning algorithms might
      not handle custom spaces properly. Use custom spaces with care.
class_docstr_tok: ["Superclass","that","is","used","to","define","observation","and","action","spaces",".","Spaces","are","crucially","used","in","Gym","to","define","the","format","of","valid","actions","and","observations",".","They","serve","various","purposes",":","*","They","clearly","define","how","to","interact","with","environments",",","i.e",".","they","specify","what","actions","need","to","look","like","and","what","observations","will","look","like","*","They","allow","us","to","work","with","highly","structured","data","(","e.g",".","in","the","form","of","elements","of",":","class",":","`","Dict","`","spaces",")","and","painlessly","transform","them","into","flat","arrays","that","can","be","used","in","learning","code","*","They","provide","a","method","to","sample","random","elements",".","This","is","especially","useful","for","exploration","and","debugging",".","Different","spaces","can","be","combined","hierarchically","via","container","spaces","(",":","class",":","`","Tuple","`","and",":","class",":","`","Dict","`",")","to","build","a","more","expressive","space","Warning",":","Custom","observation","&","action","spaces","can","inherit","from","the","``","Space","``","class",".","However",",","most","use-cases","should","be","covered","by","the","existing","space","classes","(","e.g",".",":","class",":","`","Box","`",",",":","class",":","`","Discrete","`",",","etc","...",")",",","and","container","classes","(",":","class","`","Tuple","`","&",":","class",":","`","Dict","`",")",".","Note","that","parametrized","probability","distributions","(","through","the",":","meth",":","`","Space.sample","(",")","`","method",")",",","and","batching","functions","(","in",":","class",":","`","gym.vector.VectorEnv","`",")",",","are","only","well-defined","for","instances","of","spaces","provided","in","gym","by","default",".","Moreover",",","some","implementations","of","Reinforcement","Learning","algorithms","might","not","handle","custom","spaces","properly",".","Use","custom","spaces","with","care","."]
docstr: Constructor of :class:`Space`.
  
  Args:
      shape (Optional[Sequence[int]]): If elements of the space are numpy arrays, this should specify their shape.
      dtype (Optional[Type | str]): If elements of the space are numpy arrays, this should specify their dtype.
      seed: Optionally, you can use this argument to seed the RNG that is used to sample from the space
docstr_tok: ["Constructor","of",":","class",":","`","Space","`",".","Args",":","shape","(","Optional","[","Sequence","[","int","]","]",")",":","If","elements","of","the","space","are","numpy","arrays",",","this","should","specify","their","shape",".","dtype","(","Optional","[","Type","|","str","]",")",":","If","elements","of","the","space","are","numpy","arrays",",","this","should","specify","their","dtype",".","seed",":","Optionally",",","you","can","use","this","argument","to","seed","the","RNG","that","is","used","to","sample","from","the","space"]
code: def __init__(
      self,
      shape: Optional[Sequence[int]] = None,
      dtype: Optional[Union[Type, str, np.dtype]] = None,
      seed: Optional[Union[int, np.random.Generator]] = None,
  ):
      """Constructor of :class:`Space`.
  
      Args:
          shape (Optional[Sequence[int]]): If elements of the space are numpy arrays, this should specify their shape.
          dtype (Optional[Type | str]): If elements of the space are numpy arrays, this should specify their dtype.
          seed: Optionally, you can use this argument to seed the RNG that is used to sample from the space
      """
      self._shape = None if shape is None else tuple(shape)
      self.dtype = None if dtype is None else np.dtype(dtype)
      self._np_random = None
      if seed is not None:
          if isinstance(seed, np.random.Generator):
              self._np_random = seed
          else:
              self.seed(seed)
  
file_path: gym/gym/spaces/space.py
imports: from typing import Any, Generic, Iterable, List, Mapping, Optional, Sequence, Tuple, Type, TypeVar, Union
  import numpy
  from gym.utils import seeding
label_desc: Use image node_id 1 to create a new Space object from inherited base classes: Generic with example: obj = Space(shape, dtype, seed)