class_docstr: An n-shape binary space.
  
  Elements of this space are binary arrays of a shape that is fixed during construction.
  
  Example Usage::
  
      >>> observation_space = MultiBinary(5)
      >>> observation_space.sample()
          array([0, 1, 0, 1, 0], dtype=int8)
      >>> observation_space = MultiBinary([3, 2])
      >>> observation_space.sample()
          array([[0, 0],
              [0, 1],
              [1, 1]], dtype=int8)
class_docstr_tok: ["An","n-shape","binary","space",".","Elements","of","this","space","are","binary","arrays","of","a","shape","that","is","fixed","during","construction",".","Example","Usage",":",":",">",">",">","observation_space","=","MultiBinary","(","5",")",">",">",">","observation_space.sample","(",")","array","(","[","0",",","1",",","0",",","1",",","0","]",",","dtype=int8",")",">",">",">","observation_space","=","MultiBinary","(","[","3",",","2","]",")",">",">",">","observation_space.sample","(",")","array","(","[","[","0",",","0","]",",","[","0",",","1","]",",","[","1",",","1","]","]",",","dtype=int8",")"]
docstr: Generates a single random sample from this space.
  
  A sample is drawn by independent, fair coin tosses (one toss per binary variable of the space).
  
  Args:
      mask: An optional np.ndarray to mask samples with expected shape of ``space.shape``.
          For mask == 0 then the samples will be 0 and mask == 1 then random samples will be generated.
          The expected mask shape is the space shape and mask dtype is `np.int8`.
  
  Returns:
      Sampled values from space
docstr_tok: ["Generates","a","single","random","sample","from","this","space",".","A","sample","is","drawn","by","independent",",","fair","coin","tosses","(","one","toss","per","binary","variable","of","the","space",")",".","Args",":","mask",":","An","optional","np.ndarray","to","mask","samples","with","expected","shape","of","``","space.shape","``",".","For","mask","==","0","then","the","samples","will","be","0","and","mask","==","1","then","random","samples","will","be","generated",".","The","expected","mask","shape","is","the","space","shape","and","mask","dtype","is","`","np.int8","`",".","Returns",":","Sampled","values","from","space"]
code: def sample(self, mask: Optional[np.ndarray] = None) -> np.ndarray:
      """Generates a single random sample from this space.
  
      A sample is drawn by independent, fair coin tosses (one toss per binary variable of the space).
  
      Args:
          mask: An optional np.ndarray to mask samples with expected shape of ``space.shape``.
              For mask == 0 then the samples will be 0 and mask == 1 then random samples will be generated.
              The expected mask shape is the space shape and mask dtype is `np.int8`.
  
      Returns:
          Sampled values from space
      """
      if mask is not None:
          assert isinstance(
              mask, np.ndarray
          ), f"The expected type of the mask is np.ndarray, actual type: {type(mask)}"
          assert (
              mask.dtype == np.int8
          ), f"The expected dtype of the mask is np.int8, actual dtype: {mask.dtype}"
          assert (
              mask.shape == self.shape
          ), f"The expected shape of the mask is {self.shape}, actual shape: {mask.shape}"
          assert np.all(
              (mask == 0) | (mask == 1) | (mask == 2)
          ), f"All values of a mask should be 0, 1 or 2, actual values: {mask}"
  
          return np.where(
              mask == 2,
              self.np_random.integers(
                  low=0, high=2, size=self.n, dtype=self.dtype
              ),
              mask.astype(self.dtype),
          )
  
      return self.np_random.integers(
          low=0, high=2, size=self.n, dtype=self.dtype
      )
  
file_path: gym/gym/spaces/multi_binary.py
imports: from typing import Optional, Sequence, Tuple, Union
  import numpy
  from gym.spaces.space import Space
label_desc: Use image node_id 4 for calling the MultiBinary obj's underlying member method code with example usage: obj.sample(mask) and returns: self, np