小编msg*_*sgb的帖子

Numba 基本示例比纯 python 慢

我正在尝试使用基本示例比较 numba 和纯 python,但结果很奇怪。

这是 numba 示例:

from numba import jit
from numpy import arange
from time import time
# jit decorator tells Numba to compile this function.
# The argument types will be inferred by Numba when function is called.
@jit
def sum2d(arr):
    M, N = arr.shape
    result = 0.0
    for i in range(M):
        for j in range(N):
            result += arr[i,j]
    return result

a = arange(9).reshape(3,3)
t = time()
print(sum2d(a))
print time() - t
Run Code Online (Sandbox Code Playgroud)

这是我用 numba 得到的时间 0.0469660758972 秒 …

python optimization numba

2
推荐指数
1
解决办法
917
查看次数

标签 统计

numba ×1

optimization ×1

python ×1