(observation, output_key=FLAT_OBSERVATION_KEY)
return type(observation)([(output_key, np.concatenate(observation_arrays))])
Flattens multiple observation arrays into a single numpy array.

  Args:
    observation: A mutable mapping from observation names to numpy arrays.
    output_key: The key for the flattened observation array in the output.

  Returns:
    A mutable mapping of the same type as `observation`. This will contain a
    single key-value pair consisting of `output_key` and the flattened
    and concatenated observation array.

  Raises:
    ValueError: If `observation` is not a `collections.abc.MutableMapping`.
Flattens multiple observation arrays into a single numpy array.
Flattens multiple observation arrays into a single numpy array .
def flatten_observation(observation, output_key=FLAT_OBSERVATION_KEY):
  """Flattens multiple observation arrays into a single numpy array.

  Args:
    observation: A mutable mapping from observation names to numpy arrays.
    output_key: The key for the flattened observation array in the output.

  Returns:
    A mutable mapping of the same type as `observation`. This will contain a
    single key-value pair consisting of `output_key` and the flattened
    and concatenated observation array.

  Raises:
    ValueError: If `observation` is not a `collections.abc.MutableMapping`.
  """
  if not isinstance(observation, collections.abc.MutableMapping):
    raise ValueError('Can only flatten dict-like observations.')

  if isinstance(observation, collections.OrderedDict):
    keys = observation.keys()
  else:
    # Keep a consistent ordering for other mappings.
    keys = sorted(observation.keys())

  observation_arrays = [observation[key].ravel() for key in keys]
  return type(observation)([(output_key, np.concatenate(observation_arrays))])
def flatten_observation ( observation , output_key = FLAT_OBSERVATION_KEY ) : if not isinstance ( observation , collections . abc . MutableMapping ) : raise ValueError ( 'Can only flatten dict-like observations.' ) if isinstance ( observation , collections . OrderedDict ) : keys = observation . keys ( ) else : # Keep a consistent ordering for other mappings. keys = sorted ( observation . keys ( ) ) observation_arrays = [ observation [ key ] . ravel ( ) for key in keys ] return type ( observation ) ( [ ( output_key , np . concatenate ( observation_arrays ) ) ] )