【问题标题】:Error while input an index (Python 3.6) only integers, slices (`:`), ellipsis (`...`)仅输入整数、切片 (`:`)、省略号 (`...`) 的索引 (Python 3.6) 时出错
【发布时间】:2018-11-28 06:31:19
【问题描述】:

我试图在 jupyter notebook 上运行 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 (None) and integer or boolean arrays are valid indices

【问题讨论】:

  • 在线26,action=int(input("Enter your chosen answer: "))
  • 如果有帮助,请投票并将答案标记为已接受。谢谢!

标签: python numpy tensorflow


【解决方案1】:

在文件中

D:\Codigo fuente\agent.py

第 26 行

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

action 变量是字符串类型。您需要将 action 变量转换为 int 以进行索引。

应该是

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

【讨论】:

    【解决方案2】:

    将第 26 行更改为:

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

    正如我在 cmets 中提到的那样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-25
      • 2019-06-25
      • 2021-04-16
      • 1970-01-01
      • 2018-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多