Python 3.x 强化学习。索引器:索引28超出大小为4的轴1的界限

Python 3.x 强化学习。索引器:索引28超出大小为4的轴1的界限,python-3.x,numpy,reinforcement-learning,Python 3.x,Numpy,Reinforcement Learning,我试图用下面的代码来解决一个强化学习问题。我在下面发布的代码中发现了一个错误 target_q[batch_index, actions] = rewards + self.gamma * np.max(next_q, axis=1)*dones 变量的值和形状如下所示 目标_q值为 [[-0.10855542 -0.0802312 0.06993277 0.00552639] [-0.09975365-0.07372604 0.06426253 0.00507834] [-0.123

我试图用下面的代码来解决一个强化学习问题。我在下面发布的代码中发现了一个错误

target_q[batch_index, actions] = rewards + self.gamma * np.max(next_q, axis=1)*dones
变量的值和形状如下所示

目标_q值为

[[-0.10855542 -0.0802312   0.06993277  0.00552639]
[-0.09975365-0.07372604 0.06426253 0.00507834] [-0.12322513 -0.09107337 0.07938312 0.00627324] [-0.08215004 -0.06071554 0.05292208 0.00418217] [-0.10268757 -0.07589445 0.06615258 0.00522767] [-0.11735719 -0.08673649 0.07560297 0.00597452] [-0.10855542 -0.0802312 0.06993277 0.00552639] [-0.07628225 -0.05637873 0.04914192 0.00388342] [ 0. 0. 0. 0. ] [-0.0792161-0.05854715 0.05103201 0.00403276]]带形状(10,4)

行动的价值是[28 35 45 26 40 33 40 49 34 41],具有形状(10,)

奖励的价值是[10.-20.-20.-20.-20.10.-20.-20.-20.-20.]

gamma的值为0.99

next_q的值为[[-0.08215004-0.060715540.05292208 0.00418217] [-0.10855542 -0.0802312 0.06993277 0.00552639] [-0.10855542 -0.0802312 0.06993277 0.00552639] [-0.12615901 -0.09324171 0.08127321 0.00642257] [-0.09975365 -0.07372604 0.06426253 0.00507834] [-0.0792161 -0.05854715 0.05103201 0.00403276] [-0.11735719 -0.08673649 0.07560297 0.00597452] [-0.12322513 -0.09107337 0.07938312 0.00627324] [-0.07628225 -0.05637873 0.04914192 0.00388342] [-0.10268757-0.07589445 0.06615258 0.00522767]],wiit形状(10,4)

dones的值为[1],形状为(10,)

我得到以下错误

 IndexError: index 28 is out of bounds for axis 1 with size 4. 
有人能告诉我如何解决这个错误吗


提前感谢。

不要使用太大的索引值!28比4大。知道你的维度,知道索引的价值。你建议我怎么做。你能建议一种解决方法吗?当询问错误时,准确地确定哪一行有问题。显示回溯。首先确定真正的问题。找出是什么产生了
28
索引值。
 IndexError: index 28 is out of bounds for axis 1 with size 4.