Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于10_A3C文件夹里面后三个代码文件出现如下问题:tuple indices must be integers or slices, not tuple的解决办法 #213

Open
Jing-Loog opened this issue Aug 16, 2023 · 0 comments

Comments

@Jing-Loog
Copy link

Jing-Loog commented Aug 16, 2023

原因:原本代码中有这样一行代码s = self.env.reset(),返回的s是个元组类型([ 表示状态的三个数 ], { }) 。而choose_action函数里面的s[np.newaxis, :],这是对数组s的行增加一个维度操作。而按照原本的代码,传进来的是元组,故不可行。

解决:把元组的第一个数组元素抽取出来就好:s = self.env.reset() 改为 s = self.env.reset()[0]。

此外,self.env.step(a) 这里也会出错,因为它返回的有5个值,所以得用5个变量来接收,在info后随便加个变量名就好。(反正info和要加的变量名都没有用到,所以它俩的顺序不重要。)

另外,如果启用self.env.render(),要在gym.make里加个渲染模式,这不是重点,重点是代码中有两处gym.make,都要加上,否则没用。注意:我在开启渲染后会卡住,无法显示渲染窗口。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant