0
$\begingroup$

I am trying to upgrade code for custom environment written in gym==0.18.0 to latest version of gym. My current action space and observation space are defined as

self.observation_space = np.ndarray(shape=(24,)) self.action_space = [0, 1]

I understand that in the new version the spaces have to be inherited from gym.spaces class. Can someone help me on how to rewrite my spaces (observation/action) to implement the gym.spaces?

Thanks

$\endgroup$

1 Answer 1

2
$\begingroup$

In the case of a 1D observation space, it could be something like:

self.observation_shape = (24, 1, 3)

self.observation_space = spaces.Box(low = np.zeros(self.observation_shape),  high = np.ones(self.observation_shape),dtype = np.float16)

self.action_space = spaces.Discrete(3,)

See also: https://blog.paperspace.com/creating-custom-environments-openai-gym/

$\endgroup$
1
  • $\begingroup$ Thank you. this resolved my issue. For those of you looking for exact answer it is '''' from gym import spaces import numpy as np import random space = spaces.Discrete(2,) print(space.sample()) '''' $\endgroup$
    – kumar
    Commented Sep 13, 2022 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.