hill-a / stable-baselines

A fork of OpenAI Baselines, implementations of reinforcement learning algorithms
http://stable-baselines.readthedocs.io/
MIT License
4.16k stars 725 forks source link

unflatten always gives `0` class #1196

Open wadmes opened 2 months ago

wadmes commented 2 months ago
from gymnasium.spaces import Dict, Box, Discrete
from gymnasium import spaces
observation_space = Dict({"position": Box(-1, 1, shape=(2,)), "color": Discrete(5)}, seed=42)
flatten = spaces.flatten_space(observation_space)
obs1 = flatten.sample()
unflat = spaces.utils.unflatten(observation_space,obs1)
print(obs1)
print(unflat)

obs1:

array([ 0.47568119,  0.64470851,  0.93992918,  0.0658021 ,  0.74573835,
        0.68031875, -0.96546865])

unflat:

OrderedDict({'color': 0, 'position': array([ 0.6803188 , -0.96546865], dtype=float32)})

The result of unflat will always gives color = 0, even though it is not inobs1`