Numba: High Performance Python Compiler

0.64.0 · active · verified Sat Mar 28

Numba is an open-source, NumPy-aware optimizing Just-In-Time (JIT) compiler for Python. It translates a subset of Python and NumPy code into fast machine code using the LLVM compiler library, enabling numerical algorithms to approach the speeds of C or Fortran without requiring a separate compilation step. Numba is currently at version 0.64.0 and maintains a regular release cadence, often coinciding with Python and NumPy releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the core usage of Numba's `@njit` decorator to compile a Python function for numerical computation. The function `sum_array` iterates over a NumPy array, and when decorated with `@njit`, Numba compiles it to highly optimized machine code at runtime, significantly speeding up its execution compared to pure Python.

import numpy as np
from numba import njit

@njit
def sum_array(arr):
    total = 0.0
    for x in arr:
        total += x
    return total

# Example usage
data = np.arange(1000000, dtype=np.float64)
result = sum_array(data)
print(f"Sum of array: {result}")

view raw JSON →