Other meanings of NumPy
Scientific Computing
NumPy is a fundamental Python library for numerical computing, providing a powerful N-dimensional array object, broadcasting functions, and tools for integrating C/C++ and Fortran code. It is the foundation of the scientific Python ecosystem, underpinning libraries such as SciPy, pandas, and scikit-learn.
The central object in NumPy is the ndarray, a homogeneous N-dimensional array that supports vectorized operations, enabling efficient computation without explicit loops. Arrays are stored in contiguous memory blocks, and operations are implemented in optimized C, making NumPy orders of magnitude faster than pure Python for large data. Key features include broadcasting (performing element-wise operations on arrays of different shapes), universal functions (ufuncs) that operate element-wise, and advanced indexing and slicing. NumPy also provides linear algebra routines, Fourier transforms, and random number generation.1
NumPy was created by Travis Oliphant in 2005 by merging the earlier Numeric and Numarray libraries, with the first release in 2006. It was designed to combine the best features of both predecessors while addressing their limitations. Since then, NumPy has become the de facto standard for array computing in Python, with a stable API and a strong community. The project is now part of the NumFOCUS organization and is maintained by a team of core developers. Notable milestones include the introduction of the numpy.random module overhaul in version 1.17 and the adoption of a new array function protocol in version 1.17.2
NumPy serves as the foundation for a vast ecosystem of scientific and data analysis libraries. SciPy builds on NumPy for advanced scientific computing, pandas uses NumPy arrays for data structures, and scikit-learn relies on NumPy for machine learning algorithms. Beyond these, NumPy is used in fields ranging from astronomy (Astropy) to bioinformatics (Biopython) and image processing (scikit-image). Its array interface is also implemented by other libraries like TensorFlow and PyTorch to facilitate interoperability. NumPy's influence extends to GPU computing through libraries like CuPy, which provides a NumPy-compatible API for CUDA.
NumPy includes several lesser-known features that are valuable for advanced users. The numpy.lib.stride_tricks module allows creating views with custom strides, enabling efficient sliding window operations. The numpy.ctypeslib facilitates interaction with C libraries. NumPy also supports structured arrays and record arrays for heterogeneous data, and the numpy.ma module provides masked arrays for handling missing data. A notable edge case is the np.matrix subclass, which is discouraged but still present; it enforces matrix semantics and can lead to confusion. Additionally, NumPy's np.einsum function implements Einstein summation, a powerful tool for tensor operations. The library also includes a set of numpy.testing utilities for writing unit tests.3
NumPy's performance is achieved through vectorization and memory locality, but users can further optimize by avoiding unnecessary copies, using in-place operations, and leveraging np.ndarray.view for zero-copy views. The numpy.vectorize function is often misunderstood: it does not improve performance, as it is essentially a loop. For large-scale computations, NumPy can be combined with Numba (a JIT compiler) or Cython to accelerate critical sections. The np.dot and np.matmul functions are optimized to use BLAS libraries like OpenBLAS or MKL, which can be selected at build time. NumPy also supports memory-mapped arrays (np.memmap) for handling datasets larger than RAM.
NumPy is released under the BSD license and is developed and maintained by a community of volunteers.
Help improve the encyclopedia. Reports go straight to the site manager.