class_docstr: This space represent sets of finite-length sequences.
  
  This space represents the set of tuples of the form :math:`(a_0, \dots, a_n)` where the :math:`a_i` belong
  to some space that is specified during initialization and the integer :math:`n` is not fixed
  
  Example::
      >>> space = Sequence(Box(0, 1))
      >>> space.sample()
      (array([0.0259352], dtype=float32),)
      >>> space.sample()
      (array([0.80977976], dtype=float32), array([0.80066574], dtype=float32), array([0.77165383], dtype=float32))
class_docstr_tok: ["This","space","represent","sets","of","finite-length","sequences",".","This","space","represents","the","set","of","tuples","of","the","form",":","math",":","`","(","a_0",",","\\dots",",","a_n",")","`","where","the",":","math",":","`","a_i","`","belong","to","some","space","that","is","specified","during","initialization","and","the","integer",":","math",":","`","n","`","is","not","fixed","Example",":",":",">",">",">","space","=","Sequence","(","Box","(","0",",","1",")",")",">",">",">","space.sample","(",")","(","array","(","[","0.0259352","]",",","dtype=float32",")",",",")",">",">",">","space.sample","(",")","(","array","(","[","0.80977976","]",",","dtype=float32",")",",","array","(","[","0.80066574","]",",","dtype=float32",")",",","array","(","[","0.77165383","]",",","dtype=float32",")",")"]
docstr: Generates a single random sample from this space.
  
  Args:
      mask: An optional mask for (optionally) the length of the sequence and (optionally) the values in the sequence.
          If you specify `mask`, it is expected to be a tuple of the form `(length_mask, sample_mask)` where `length_mask`
          is
          - `None` The length will be randomly drawn from a geometric distribution
          - `np.ndarray` of integers, in which case the length of the sampled sequence is randomly drawn from this array.
          - `int` for a fixed length sample
          The second element of the mask tuple `sample` mask specifies a mask that is applied when
          sampling elements from the base space. The mask is applied for each feature space sample.
  
  Returns:
      A tuple of random length with random samples of elements from the :attr:`feature_space`.
docstr_tok: ["Generates","a","single","random","sample","from","this","space",".","Args",":","mask",":","An","optional","mask","for","(","optionally",")","the","length","of","the","sequence","and","(","optionally",")","the","values","in","the","sequence",".","If","you","specify","`","mask","`",",","it","is","expected","to","be","a","tuple","of","the","form","`","(","length_mask",",","sample_mask",")","`","where","`","length_mask","`","is","-","`","None","`","The","length","will","be","randomly","drawn","from","a","geometric","distribution","-","`","np.ndarray","`","of","integers",",","in","which","case","the","length","of","the","sampled","sequence","is","randomly","drawn","from","this","array",".","-","`","int","`","for","a","fixed","length","sample","The","second","element","of","the","mask","tuple","`","sample","`","mask","specifies","a","mask","that","is","applied","when","sampling","elements","from","the","base","space",".","The","mask","is","applied","for","each","feature","space","sample",".","Returns",":","A","tuple","of","random","length","with","random","samples","of","elements","from","the",":","attr",":","`","feature_space","`","."]
code: def sample(
      self,
      mask: Optional[
          Tuple[Optional[Union[np.ndarray, int]], Optional[Any]]
      ] = None,
  ) -> Tuple[Any]:
      """Generates a single random sample from this space.
  
      Args:
          mask: An optional mask for (optionally) the length of the sequence and (optionally) the values in the sequence.
              If you specify `mask`, it is expected to be a tuple of the form `(length_mask, sample_mask)` where `length_mask`
              is
              - `None` The length will be randomly drawn from a geometric distribution
              - `np.ndarray` of integers, in which case the length of the sampled sequence is randomly drawn from this array.
              - `int` for a fixed length sample
              The second element of the mask tuple `sample` mask specifies a mask that is applied when
              sampling elements from the base space. The mask is applied for each feature space sample.
  
      Returns:
          A tuple of random length with random samples of elements from the :attr:`feature_space`.
      """
      if mask is not None:
          length_mask, feature_mask = mask
      else:
          length_mask, feature_mask = None, None
  
      if length_mask is not None:
          if np.issubdtype(type(length_mask), np.integer):
              assert (
                  0 <= length_mask
              ), f"Expects the length mask to be greater than or equal to zero, actual value: {length_mask}"
              length = length_mask
          elif isinstance(length_mask, np.ndarray):
              assert (
                  len(length_mask.shape) == 1
              ), f"Expects the shape of the length mask to be 1-dimensional, actual shape: {length_mask.shape}"
              assert np.all(
                  0 <= length_mask
              ), f"Expects all values in the length_mask to be greater than or equal to zero, actual values: {length_mask}"
              length = self.np_random.choice(length_mask)
          else:
              raise TypeError(
                  f"Expects the type of length_mask to an integer or a np.ndarray, actual type: {type(length_mask)}"
              )
      else:
          # The choice of 0.25 is arbitrary
          length = self.np_random.geometric(0.25)
  
      return tuple(
          self.feature_space.sample(mask=feature_mask)
          for _ in range(length)
      )
  
file_path: gym/gym/spaces/sequence.py
imports: from collections.abc import Sequence
  from typing import Any, List, Optional, Tuple, Union
  import numpy
  import gym
  from gym.spaces.space import Space
label_desc: Use image node_id 4 for calling the Sequence obj's underlying member method code with example usage: obj.sample(mask) and returns: tuple