使用 numpy.fill 与 Numba 'nopython' 模式



>我正在尝试使用 numpy 填充函数来填充 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

然而,numpy fill 函数在设置 nopython=True 时仍然会给出属性错误。它适用于nopython=False。