# Code from http://numba.pydata.org from numba import jit from numpy import arange # 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) print(sum2d(a))
After talking to someone who'd actually used Numba in their code, they say their code saw anywhere from 2x to 500x speed improvements depending on what they were doing (using regular, old vanilla Python). That's really impressive. I can't wait to try out Numba, and I think I have some very interesting use cases coming up where this might be the solution I've been looking for.