我正在尝试使用 numpy fill 函数来填充 ndarray 中的值。我在使用 Numba 的函数下有这个,但出现属性错误。这是我的代码示例:
@jit(nopython=True)
def computething(param1):
x = np.sum(param1)
x1 = np.zeros(10)
x1.fill(x)
*请注意,这只是示例代码。
我收到以下错误:
UntypedAttributeError: Unknown attribute 'fill' of type array(float64, 1d, C)
如何防止此错误?谢谢你!
最佳答案
一个可行的解决方案是:
@jit(nopython=True)
def computething(param1):
x = np.sum(param1)
x1 = np.zeros(10)
x1[:] = x
然而,当设置 nopython=True 时,numpy fill 函数仍然会给出属性错误。使用 nopython=False 可以正常工作。
关于python - 将 numpy.fill 与 Numba 'nopython' 模式结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59869312/