Overview

NumPy 2.0, released on June 17, 2024, is a major release introducing StringDType, a C API cleanup, and removal of deprecated functions.

Main Features

StringDType

The new StringDType replaces the old fixed-size strings with a more performant and flexible variable-length type.

python
import numpy as np

# New StringDType (variable-length)
arr = np.array(['hello', 'world'], dtype=np.dtypes.StringDType())
print(arr.dtype)  # StringDType
print(arr[0])    # hello

C API cleanup

The C API has been cleaned up with removal of deprecated symbols. C extensions must be recompiled.

python
import numpy as np

# Functions renamed or removed in 2.0
# np.string_ -> np.bytes_
# np.unicode_ -> np.str_
# np.product -> np.prod (removed)

print(np.__version__)  # 2.0.x
print(np.prod([1, 2, 3, 4]))  # 24

Removed deprecated functions

Many long-deprecated aliases and functions have been removed to streamline the API.

python
import numpy as np

# Removed: np.bool, np.int, np.float, np.complex
# Use: bool, int, float, complex
# Or: np.bool_, np.int_, np.float64, np.complex128

arr = np.array([1.0, 2.0], dtype=np.float64)
print(arr.dtype)  # float64

Sources