Array API standard compatibility#

The NumPy 2.3.0 main namespace as well as thenumpy.fft andnumpy.linalgnamespaces are compatible with the2024.12 versionof the Python array API standard.

NumPy aims to implement support for the future versions of the standard- assuming that those future versions can be upgraded to given NumPy’sbackwards compatibility policy.

For usage guidelines for downstream libraries and end users who want to writecode that will work with both NumPy and other array libraries, we refer to thedocumentation of the array API standard itself and to code anddeveloper-focused documentation in SciPy and scikit-learn.

Note that in order to use standard-complaint code with older NumPy versions(< 2.0), thearray-api-compat package may be useful. Fortesting whether NumPy-using code is only using standard-compliant featuresrather than anything NumPy-specific, thearray-api-strict package can be used.

History

NumPy 1.22.0 was the first version to include support for the array APIstandard, via a separatenumpy.array_api submodule. This module wasmarked as experimental (it emitted a warning on import) and removed inNumPy 2.0 because full support (2022.12 version[1]) was included inthe main namespace.NEP 47 andNEP 56describe the motivation and scope for implementing the array API standardin NumPy.

Entry point#

NumPy installs anentry pointthat can be used for discovery purposes:

>>>fromimportlib.metadataimportentry_points>>>entry_points(group='array_api',name='numpy')[EntryPoint(name='numpy', value='numpy', group='array_api')]

Note that leaving outname='numpy' will cause a list of entry points to bereturned for all array API standard compatible implementations that installedan entry point.

Footnotes

[1]

With a few very minor exceptions, as documented inNEP 56.Thesum,prod andtrace behavior adheres to the 2023.12 versioninstead, as do function signatures; the only known incompatibility that mayremain is that the standard forbids unsafe casts for in-place operatorswhile NumPy supports those.

Inspection#

NumPy implements thearray API inspection utilities.These functions can be accessed via the__array_namespace_info__()function, which returns a namespace containing the inspection utilities.

__array_namespace_info__()

Get the array API inspection namespace for NumPy.