有没有类似于 gym.spaces.Box 的东西在 numpy.



在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是否带有类似空格的东西。盒子类也是?

我不知道

函数,但自己写很容易。

import numpy as np
np.all(np.less_equal(low, observation)) and np.all(np.greater_equal(observation, high))

这将检查所有观测值是否都在指定范围内。如果省略np.all则可以看到哪个维度有问题。

最新更新