Files
Gymnasium/gym/wrappers/clip_action.py
Xingdong Zuo fcb58232e6 [Wrappers]: add ClipAction (#1483)
* Create clip_action.py

* Update __init__.py

* Create test_clip_action.py

* Update clip_action.py

* Update test_clip_action.py

* Update test_clip_action.py

* Update test_clip_action.py

* Update __init__.py

* Update test_clip_action.py
2019-06-07 15:56:56 -07:00

15 lines
408 B
Python

import numpy as np
from gym import ActionWrapper
from gym.spaces import Box
class ClipAction(ActionWrapper):
r"""Clip the continuous action within the valid bound. """
def __init__(self, env):
assert isinstance(env.action_space, Box)
super(ClipAction, self).__init__(env)
def action(self, action):
return np.clip(action, self.action_space.low, self.action_space.high)