Numba is an open-source just-in-time (JIT) compiler for Python that translates Python functions and NumPy array operations into optimized machine code using the LLVM compiler. Sponsored by Anaconda, Numba specializes in numerical and scientific computing where performance is critical, offering substantial speedups (often 10–100×) with minimal code changes. The key insight is that Numba targets array-oriented numerical code particularly well — loops over NumPy arrays, mathematical computations, and parallel operations that would be slow in pure Python execute at speeds approaching C or Fortran. As of Numba 0.65.x (2026), @jit defaults to nopython mode, the built-in CUDA target is deprecated in favor of the numba-cuda package, and experimental free-threading (Python 3.14t) support has been added.
What This Cheat Sheet Covers
This topic spans 20 focused tables and 191 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Core JIT Decorators
The decorator you choose is the most consequential decision when using Numba — it determines compilation mode, target device, and output type. Start with @njit for CPU numerical code, and reach for @vectorize or @cuda.jit only when you specifically need ufuncs or GPU execution.
| Decorator | Example | Description |
|---|---|---|
def f(x): return x + 1 | • Alias for @jit(nopython=True) — the recommended default • forces nopython mode and raises error immediately if compilation fails instead of falling back. | |
def f(x): return x * 2 | • Compiles using lazy JIT compilation (on first call) • since Numba 0.59, defaults to nopython mode (no longer falls back to object mode automatically). | |
def compute(a, b): return a @ b | • Equivalent to @njit• explicit form still widely seen in older code • Redundant since 0.59 but still valid and readable | |
def add(x, y): return x + y | • Eager compilation with explicit type signature • compiles immediately at definition time rather than on first call. | |
def square(x): return x ** 2 | • Creates a NumPy universal function (ufunc) from a scalar function • automatically broadcasts over arrays element-wise; supports cpu, parallel, and cuda targets. |