【问题标题】:Numba - TypeError: 'type' object has no attribute '__getitem__Numba - TypeError:'type'对象没有属性'__getitem__
【发布时间】:2013-11-09 22:05:13
【问题描述】:

我在 Anaconda 中使用 Numba,不知道为什么

@jit(argtypes=[int16[:], int16[:]])
def index(ic, nc):
    return ic[0] + nc[0] * (ic[1] + nc[1] * ic[2])

不起作用:

TypeError: 'type' object has no attribute '__getitem__'

但是如果我使用@autojit 而不是@jit(..) 一切都很好。

【问题讨论】:

    标签: typeerror jit numba


    【解决方案1】:

    阅读 Numba 示例有点让人困惑,但您实际上需要从 numba 命名空间导入 int16

    您看到的错误与从 NumPy 导入 int16 一致。因此,如果在文件的顶部,您的代码如下所示:

    from numba import *
    from numpy import *
    

    然后你会不小心用它的 NumPy 定义覆盖 int16。有两个修复。首先,您可以交换导入的顺序:

    from numpy import *
    from numba import *
    

    或者,更准确地说,您可以导入不带 * 的命名空间并明确引用您需要的内容:

    import numba as nb
    
    @nb.jit(argtypes=[nb.int16[:], nb.int16[:]])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-04
      • 2012-10-15
      • 2014-01-16
      • 2017-02-27
      • 2018-01-28
      • 2014-06-10
      • 2012-10-16
      • 2015-11-04
      相关资源
      最近更新 更多