Skip to content

Instantly share code, notes, and snippets.

@colllin
Created August 19, 2020 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colllin/1172e042edf267d5ec667fa9802673cf to your computer and use it in GitHub Desktop.
Save colllin/1172e042edf267d5ec667fa9802673cf to your computer and use it in GitHub Desktop.
OpenAI Gym FlattenAction wrapper
import gym
class FlattenAction(gym.ActionWrapper):
"""Action wrapper that flattens the action."""
def __init__(self, env):
super(FlattenAction, self).__init__(env)
self.action_space = gym.spaces.utils.flatten_space(self.env.action_space)
def action(self, action):
return gym.spaces.utils.unflatten(self.env.action_space, action)
def reverse_action(self, action):
return gym.spaces.utils.flatten(self.env.action_space, action)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment