【问题标题】:Error: 'float' object cannot be interpreted as an index错误:“浮动”对象不能解释为索引
【发布时间】:2020-06-04 15:58:53
【问题描述】:

我正在尝试从此存储库中运行以下代码。

https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library

hp.visualize(images, column=3, fig_size=(20,10))

它给了我以下错误。我该如何解决这个问题?

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "Helpers.py", line 51, in visualize
    f,axes= plt.subplots(row, column, figsize=fig_size)
  File "/home/.local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 1187, in subplots
    gridspec_kw=gridspec_kw)
  File "/home/.local/lib/python2.7/site-packages/matplotlib/figure.py", line 1362, in subplots
    axarr = np.empty((nrows, ncols), dtype=object)
TypeError: 'float' object cannot be interpreted as an index

【问题讨论】:

标签: python numpy floating-point


【解决方案1】:

我相信您尝试使用的 repo 需要 Python3.x(尽管在任何地方都没有明确提及)并且您似乎正在使用 Python2.7

错误

TypeError: 'float' 对象不能被解释为索引

在我看来,该行中的一个参数正在传递一个浮点值作为索引,这在Python2.x 中不被接受,在Python3.x 中会很好。

只需使用Python3.x 即可解决您的问题。

【讨论】:

  • 感谢您的回答,您能告诉我如何为这个特定代码指定 python 3 吗?当我运行程序时,它默认使用 python 2。
  • 您在使用 Jupyter Notebook 吗?如果是这样,只需将其配置为使用 python3,请参阅here
  • 我正在使用 Pycharm。如何在 Pycharm 上配置它?
  • 使用python3。查看如何为 pycharm 安装和使用 python3。或者,您可能还希望像在 github repo 中那样在 Jupiter notebook 中执行此操作。
  • 我的 Pycharm 基于 python 3。但是,当我使用 Pycharm 终端运行代码时,它会自动使用 Python v2。我不知道为什么会这样。
猜你喜欢
  • 1970-01-01
  • 2018-12-15
  • 2021-12-26
  • 2015-06-18
  • 2015-04-01
  • 1970-01-01
  • 2018-05-14
  • 1970-01-01
  • 2021-12-05
相关资源
最近更新 更多