仅输入整数、片(`:`)、省略号(`…`)的索引(Python3.6)时出错

2024-10-03 04:36:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着在jupyter笔记本上运行https://github.com/AppliedDataSciencePartners/DeepReinforcementLearning,在执行这个块之前一切都很好。你知道吗

from game import Game
from funcs import playMatchesBetweenVersions

import loggers as lg

env = Game()

playMatchesBetweenVersions(env, 2, -1, 26, 1, lg.logger_tourney,0, 1)

其中重要的一点是-1对于一个人类玩家来说,如果我运行这个,就会发生这种情况。Ask for imput

当输入一个有效的输入时,就会发生这种情况。IndexError: only integers, slices (^{}), ellipsis (^{}), numpy.newaxis (^{}) and integer or boolean arrays are valid indices


Tags: fromhttpsimportgithubenvcomgame情况
2条回答

在文件中

D:\Codigo fuente\agent.py

第26行

action = input('Enter your chosen action: ')

action变量的类型为string。需要将action变量转换为int进行索引。你知道吗

应该是的

action = int(input('Enter your chosen action: '))

将第26行改为:

action=int(input("Enter your chosen answer: "))

正如我在评论中提到的。你知道吗

相关问题 更多 >