在OpenAI健身房,您可以这样做:
from gym import spaces
low = [1, 2, 3]
high = [4, 4, 4]
box = spaces.Box(np.array(low), np.array(high))
observation = np.array([2, 2, 2])
if not box.contains(observation):
print("This is invalid!")
它基本上检查每个维度
def contains(self, obs):
n = len(obs) # == len(low) == len(high)
for i in range(n):
if not (self.low[i] <= obs[i] <= self.high[i]):
return False
return True
numpy是否也有类似spaces.Box类的东西?
答案 0 :(得分:1)
我不知道某个功能,但很容易自己写。
import numpy as np
np.all(np.less_equal(low, observation)) and np.all(np.greater_equal(observation, high))
检查所有观察是否在指定范围内。如果省略np.all
,则可以看到哪个维度是问题。