整数标量数组可以转换为标量索引

integer scalar arrays can be converted to a scalar index

我正在尝试在 this blog post that I found on Medium.com. In my (python class) 之后创建一个 Q table 来创建一个自定义的开放式 AI Gym 环境,我的操作 space self.action_space 将是 3 个可能的操作,可能的观察值将是 50 到 150 的值,增量为 1 self.observation_space

    #possible actions from more_heat less heat functions
    self.action_space = np.array([ 0,  1,  2])

    #possible deviation values from temp - setpoint
    self.observation_space = np.arange(50,150,1)

我关注的博客 post 通过这段代码创建了 Q table,我认为下面的代码只是根据大小创建一个零数组。

action_size = env.action_space.n
state_size = env.observation_space.n

qtable = np.zeros((state_size, action_size))
print(qtable)

但是当我尝试打印 Q table 时,出现了这个错误: TypeError: only integer scalar arrays can be converted to a scalar index

如果有智者指出我做错了什么,将不胜感激!

同样的错误只是 运行 这个代码:

import numpy as np
action_space = np.array([0,1,2])
observation_space = np.arange(50,150,1)

action_size = action_space
state_size = observation_space

qtable = np.zeros((state_size, action_size))
print(qtable)

使用env.observation_space.shape[0]获得状态space大小。与操作 space 相同。

在您链接的博客 post 中,他们解决了 the frozen lake task. The task inherits from the discrete class 定义动作和 obs space 的问题

    self.action_space = spaces.Discrete(self.nA)

他们的 Discrete class 有一个属性 n 指定离散 space 的大小。 相反,您使用 np.array 而不是。当您尝试执行

时,您实际上应该会收到错误消息
    action_size = env.action_space.n

或者至少,如果我尝试 运行 你的代码,我会这样做。