在用numba` @ jit(nopython = True)`装饰的函数中创建`NumPy`数组? [英] Creating `NumPy` arrays inside a function decorated with `numba`'s `@jit(nopython=True)`?
本文介绍了在用numba` @ jit(nopython = True)`装饰的函数中创建`NumPy`数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在用numba
的@jit(nopython=True)
装饰的函数内创建一个numpy数组.例如:
I would like to create a numpy array inside a function decorated with numba
's @jit(nopython=True)
. For example:
import numpy as np
import numba
@numba.jit(nopython=True)
def funny_func():
zero_array = np.zeros(10)
sum_result = 0
for elem in zero_array:
sum_result += elem
return sum_result
print funny_func()
编译此脚本会产生以下错误:
Compiling this script creates the following error:
UntypedAttributeError: Unknown attribute "zeros" of type Module(<module
'numpy' from 'A:\Anaconda\lib\site-packages\numpy\__init__.pyc'>)
因此,numba
不支持NumPy
数组创建功能.然后,如何在经过修饰的"numba
函数"内部创建NumPy
数组?
So, numba
does't support NumPy
array creation functions. How then do I create NumPy
arrays inside such a decorated "numba
function"?
推荐答案
查看全文