簡體   English   中英

是否有與numpy中的gym.spaces.Box類似的東西?

[英]Is there something similar as gym.spaces.Box in 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是否也帶有spaces.Box類之類的東西?

我不知道函數,但是編寫自己很容易。

import numpy as np

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

這將檢查所有觀察值是否在指定范圍內。 如果省略np.all ,則可以看到問題所在的維度。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM