[英]Is there something similar as gym.spaces.Box in numpy?
In the OpenAI gym, you can do something like this: 在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!")
It basically checks for each dimension 它基本上检查每个维度
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
Does numpy come with something like the spaces.Box class as well? numpy是否也带有spaces.Box类之类的东西?
I do not know about a function, but it is easy to write yourself. 我不知道函数,但是编写自己很容易。
import numpy as np
np.all(np.less_equal(low, observation)) and np.all(np.greater_equal(observation, high))
This checks if all observations are inside the specified bounds. 这将检查所有观察值是否在指定范围内。 If you omit the np.all
you can see which dimension was the problem. 如果省略np.all
,则可以看到问题所在的维度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.