(observation_spaces, observation_excluded=())
Flattens the dictionary observation spaces to gym.spaces.Box.

  If observation_excluded is passed in, it will still return a dictionary,
  which includes all the (key, observation_spaces[key]) in observation_excluded,
  and ('other': the flattened Box space).

  Args:
    observation_spaces: A dictionary of all the observation spaces.
    observation_excluded: A list/tuple of all the keys of the observations to be
      ignored during flattening.

  Returns:
    A box space or a dictionary of observation spaces based on whether
      observation_excluded is empty.
Flattens the dictionary observation spaces to gym.spaces.Box.
Flattens the dictionary observation spaces to gym . spaces . Box .
def flatten_observation_spaces(observation_spaces, observation_excluded=()):
  """Flattens the dictionary observation spaces to gym.spaces.Box.

  If observation_excluded is passed in, it will still return a dictionary,
  which includes all the (key, observation_spaces[key]) in observation_excluded,
  and ('other': the flattened Box space).

  Args:
    observation_spaces: A dictionary of all the observation spaces.
    observation_excluded: A list/tuple of all the keys of the observations to be
      ignored during flattening.

  Returns:
    A box space or a dictionary of observation spaces based on whether
      observation_excluded is empty.
  """
  if not isinstance(observation_excluded, (list, tuple)):
    observation_excluded = [observation_excluded]
  lower_bound = []
  upper_bound = []
  for key, value in observation_spaces.spaces.items():
    if key not in observation_excluded:
      lower_bound.append(np.asarray(value.low).flatten())
      upper_bound.append(np.asarray(value.high).flatten())
  lower_bound = np.concatenate(lower_bound)
  upper_bound = np.concatenate(upper_bound)
  observation_space = spaces.Box(
      np.array(lower_bound), np.array(upper_bound), dtype=np.float32)
  if not observation_excluded:
    return observation_space
  else:
    observation_spaces_after_flatten = {"other": observation_space}
    for key in observation_excluded:
      observation_spaces_after_flatten[key] = observation_spaces[key]
    return spaces.Dict(observation_spaces_after_flatten)
def flatten_observation_spaces ( observation_spaces , observation_excluded = ( ) ) : if not isinstance ( observation_excluded , ( list , tuple ) ) : observation_excluded = [ observation_excluded ] lower_bound = [ ] upper_bound = [ ] for key , value in observation_spaces . spaces . items ( ) : if key not in observation_excluded : lower_bound . append ( np . asarray ( value . low ) . flatten ( ) ) upper_bound . append ( np . asarray ( value . high ) . flatten ( ) ) lower_bound = np . concatenate ( lower_bound ) upper_bound = np . concatenate ( upper_bound ) observation_space = spaces . Box ( np . array ( lower_bound ) , np . array ( upper_bound ) , dtype = np . float32 ) if not observation_excluded : return observation_space else : observation_spaces_after_flatten = { "other" : observation_space } for key in observation_excluded : observation_spaces_after_flatten [ key ] = observation_spaces [ key ] return spaces . Dict ( observation_spaces_after_flatten )