Accelerate Python Functions
Numba translates Python functions to optimized machine code at runtime using the
industry-standard LLVM compiler library. Numba-compiled numerical algorithms in Python can approach the speeds of C or FORTRAN.
You don’t need to replace the Python interpreter, run a separate compilation step, or even
have a C/C++ compiler installed. Just apply one of the Numba decorators to your Python function, and Numba does the rest.
from numba import njit
import random
@njit
def monte_carlo_pi(nsamples):
acc = 0
for i in range(nsamples):
x = random.random()
y = random.random()
if (x ** 2 + y ** 2) < 1.0:
acc += 1
return 4.0 * acc / nsamples
Built for Scientific Computing
Numba is designed to be used with NumPy arrays and functions. Numba generates specialized code for
different array data types and layouts to optimize performance. Special decorators can create universal functions that broadcast over NumPy arrays just like NumPy functions do.
Numba also works great with Jupyter notebooks for interactive computing, and with distributed execution