Overview

NumPy 1.20, released on January 31, 2021, is the first version to ship type annotation stubs and brings SIMD acceleration for many universal functions.

Main Features

Type annotation stubs

NumPy now ships .pyi files that let tools like mypy and IDEs statically check code using NumPy. Array types, dtypes, and core functions are annotated.

python
import numpy as np
import numpy.typing as npt

# Type annotations for NumPy arrays
def normalize(data: npt.NDArray[np.float64]) -> npt.NDArray[np.float64]:
    """Normalize an array between 0 and 1."""
    minimum = data.min()
    maximum = data.max()
    return (data - minimum) / (maximum - minimum)

values = np.array([10.0, 20.0, 30.0, 40.0, 50.0])
result = normalize(values)
print(result)  # [0.   0.25 0.5  0.75 1.  ]

# mypy can now check:
# - argument types passed to numpy functions
# - return types of operations

SIMD acceleration

NumPy 1.20 enables SIMD instructions (SSE, AVX, NEON) to speed up universal functions (ufuncs) like np.sin, np.exp, and arithmetic operations. Gains are significant on large arrays.

python
import numpy as np

# Ufuncs are automatically SIMD-accelerated
data = np.random.randn(1_000_000)

# These operations benefit from SIMD acceleration
sines = np.sin(data)
exponentials = np.exp(data)
absolutes = np.abs(data)

# Check detected SIMD capabilities
print(np.show_config())
# Shows detected optimizations (SSE2, AVX2, etc.)

Sources