e01.org

NumPy

NumPy (pronounced ) is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays. The predecessor of NumPy, Numeric, was originally created by Jim Hugunin with contributions from several other developers. In 2005, Travis Oliphant created NumPy by incorporating features of the competing Numarray into Numeric, with extensive modifications. NumPy is open-source software and has many contributors. NumPy is fiscally sponsored by NumFOCUS.

NumPy (pronounced ) is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays. The predecessor of NumPy, Numeric, was originally created by Jim Hugunin with contributions from several other developers. In 2005, Travis Oliphant created NumPy by incorporating features of the competing Numarray into Numeric, with extensive modifications. NumPy is open-source software and has many contributors. NumPy is fiscally sponsored by NumFOCUS. ===matrix-sig=== The Python programming language was not originally designed for numerical computing, but attracted the attention of the scientific and engineering community early on. In 1995 the special interest group (SIG) matrix-sig was founded with the aim of defining an array computing package; among its members was Python designer and maintainer Guido van Rossum, who extended Python's syntax (in particular the indexing syntax ) to make array computing easier. ===Numeric=== An implementation of a matrix package was completed by Jim Fulton, then expanded to support multi-dimensional arrays by Jim Hugunin and called Numeric (also variously known as the "Numerical Python extensions" or "NumPy"), with influences from the APL family of languages, Basis, MATLAB, FORTRAN, S and S+, and others. Hugunin, a graduate student at the Massachusetts Institute of Technology (MIT), joined the Corporation for National Research Initiatives (CNRI) in 1997 to work on JPython, leaving Paul Dubois of Lawrence Livermore National Laboratory (LLNL) to take over as maintainer. Other early contributors include David Ascher, Konrad Hinsen and Travis Oliphant. ===Numarray=== A new package called Numarray was written as a more flexible replacement for Numeric. Like Numeric, it too is now deprecated. Numarray had faster operations for large arrays, but was slower than Numeric on small ones, so for a time both packages were used in parallel for different use cases. The last version of Numeric (v24.2) was released on 11 November 2005, while the last version of numarray (v1.5.2) was released on 24 August 2006. There was a desire to get Numeric into the Python standard library, but Guido van Rossum decided that the code was not maintainable in its state then. ===NumPy=== In early 2005, NumPy developer Travis Oliphant wanted to unify the community around a single array package and ported Numarray's features to Numeric, releasing the result as NumPy 1.0 in 2006. This new project was part of SciPy. To avoid installing the large SciPy package just to get an array object, this new package was separated and called NumPy. Support for Python 3 was added in 2011 with NumPy version 1.5.0. In 2011, PyPy started development on an implementation of the NumPy API for PyPy. As of 2023, it is not yet fully compatible with NumPy. ===Limitations=== Inserting or appending entries to an array is not as trivially possible as it is with Python's lists. The routine to extend arrays actually creates new arrays of the desired shape and padding values, copies the given array into the new one and returns it. NumPy's operation does not actually link the two arrays but returns a new one, filled with the entries from both given arrays in sequence. Reshaping the dimensionality of an array with is only possible as long as the number of elements in the array does not change. These circumstances originate from the fact that NumPy's arrays must be views on contiguous memory buffers. Algorithms that are not expressible as a vectorized operation will typically run slowly because they must be implemented in "pure Python", while vectorization may increase memory complexity of some operations from constant to linear, because temporary arrays must be created that are as large as the inputs. Runtime compilation of numerical code has been implemented by several groups to avoid these problems; open source solutions that interoperate with NumPy include numexpr and Numba. Cython and Pythran are static-compiling alternatives to these. Many modern large-scale scientific computing applications have requirements that exceed the capabilities of the NumPy arrays. For example, NumPy arrays are usually loaded into a computer's memory, which might have insufficient capacity for the analysis of large datasets. Further, NumPy operations are executed on a single CPU. However, many linear algebra operations can be accelerated by executing them on clusters of CPUs or on specialized hardware, such as GPUs and TPUs, which many deep learning applications rely on. As a result, several alternative array implementations have arisen in the scientific python ecosystem over the recent years, such as Dask for distributed arrays and TensorFlow or JAX for computations on GPUs. Because of its popularity, these often implement a subset of NumPy's API or mimic it, so that users can change their array implementation with minimal changes to their code required. A library named CuPy, accelerated by Nvidia's CUDA framework, has also shown potential for faster computing, being a 'drop-in replacement' of NumPy. import numpy as np from numpy.typing import NDArray a: NDArray[int] = np.array([[1, 2, 3, 4], [3, 4, 6, 7], [5, 9, 0, 5 ) a.transpose() from numpy.typing import NDArray a: NDArray[int] = np.array([1, 2, 3, 6]) b: NDArray[int] = np.linspace(0, 2, 4) # create an array with four equally spaced points starting with 0 and ending with 2. c: NDArray[int] = a - b print(c) prints array([ 1. , 1.33333333, 1.66666667, 4. ]) print(a ** 2) prints array([ 1, 4, 9, 36]) from numpy.typing import NDArray, float64 a: NDArray[float64] = np.linspace(-np.pi, np.pi, 100) b: float64 = np.sin(a) c: float64 = np.cos(a) Functions can take both numbers and arrays as parameters. print(np.sin(1)) prints 0.8414709848078965 print(np.sin(np.array([1, 2, 3]))) prints array([0.84147098, 0.90929743, 0.14112001]) import numpy as np from numpy.linalg import solve, inv from numpy.random import rand from numpy.typing import NDArray, float32 a: NDArray[float32] = np.array([[1, 2, 3], [3, 4, 6.7], [5, 9.0, 5 ) print(a.transpose()) prints: array([[ 1. , 3. , 5. ], [ 2. , 4. , 9. ], [ 3. , 6.7, 5. ) print(inv(a)) prints: array([[-2.27683616, 0.96045198, 0.07909605], [ 1.04519774, -0.56497175, 0.1299435 ], [ 0.39548023, 0.05649718, -0.11299435 ) b: NDArray[int] = np.array([3, 2, 1]) print(solve(a, b)) # solve the equation ax = b prints array([-4.83050847, 2.13559322, 1.18644068]) c: NDArray[float32] = rand(3, 3) * 20 # create a 3x3 random matrix of values within [0,1] scaled by 20 print(c) prints: array([[ 3.98732789, 2.47702609, 4.71167924], [ 9.24410671, 5.5240412 , 10.6468792 ], [ 10.38136661, 8.44968437, 15.17639591 ) print(np.dot(a, c)) # matrix multiplication prints: array([[ 53.61964114, 38.8741616 , 71.53462537], [ 118.4935668 , 86.14012835, 158.40440712], [ 155.04043289, 104.3499231 , 195.26228855 ) print(a @ c) # Starting with Python 3.5 and NumPy 1.10 prints: array([[ 53.61964114, 38.8741616 , 71.53462537], [ 118.4935668 , 86.14012835, 158.40440712], [ 155.04043289, 104.3499231 , 195.26228855 ) import numpy as np from numpy.typing import NDArray, float64 M: NDArray[float64] = np.zeros(shape=(2, 3, 5, 7, 11)) T: NDArray[float64] = np.transpose(M, (4, 2, 1, 3, 0)) print(T.shape) prints (11, 5, 3, 7, 2) import cv2 import numpy as np from numpy.typing import NDArray, float32 r: NDArray[float32] = np.reshape(np.arange(256*256)%256,(256,256)) # 256x256 pixel array with a horizontal gradient from 0 to 255 for the red color channel g: NDArray[float32] = np.zeros_like(r) # array of same size and type as r but filled with 0s for the green color channel b: NDArray[float32] = r.T # transposed r will give a vertical gradient for the blue color channel print(cv2.imwrite("gradients.png", np.dstack([b,g,r]))) # OpenCV images are interpreted as BGR, the depth-stacked array will be written to an 8bit RGB PNG-file called "gradients.png" prints True Functional Python ### from typing import Callable points: list[list[int = [[9,2,8],[4,7,2],[3,4,4],[5,6,9],[5,0,7],[8,2,7],[0,3,2],[7,3,0],[6,1,1],[2,9,6 qPoint: list[int] = [4,5,3] Lambda function for calculating the Euclidean distance of two vectors edistance: Callable[[list[float], list[float , float] = lambda a, b: sum((a1 - b1) ** 2 for a1, b1 in zip(a, b)) ** 0.5 Compute all Euclidean distances at once and return the nearest point nearest: list[int] = min((edistance(i, qpoint), i) for i in points)[1] print(f"Nearest point to q: {nearest}") prints Nearest point to q: [3, 4, 4] Equivalent NumPy vectorization ### import numpy as np from numpy.typing import NDArray points: NDArray[int] = np.array([[9,2,8],[4,7,2],[3,4,4],[5,6,9],[5,0,7],[8,2,7],[0,3,2],[7,3,0],[6,1,1],[2,9,6 ) qPoint: NDArray[int] = np.array([4,5,3]) minIdx: int = np.argmin(np.linalg.norm(points-qPoint, axis=1)) # compute all euclidean distances at once and return the index of the smallest one print(f"Nearest point to q: {points[minIdx]}") prints Nearest point to q: [3 4 4] ! Python Fortran native code call example ! f2py -c -m foo *.f90 ! Compile Fortran into python named module using intent statements ! Fortran subroutines only not functions--easier than JNI with C wrapper ! requires gfortran and make subroutine ftest(a, b, n, c, d) implicit none integer, intent(in) :: a, b, n integer, intent(out) :: c, d integer :: i c = 0 do i = 1, n c = a + b + c end do d = (c * n) * (-1) end subroutine ftest import foo import numpy as np a: tuple[int, int] = foo.ftest(1, 2, 3) # or c,d = instead of a.c and a.d print(a) prints (9,-27) help("foo.ftest") prints the foo.ftest.__doc__

References

  1. ^ "Numarray Homepage" . Retrieved 2006-06-24 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1151103600.0
  2. ^ Travis Oliphant and other SciPy developers. "[Numpy-discussion] Status of Numeric" . Retrieved 2 February 2017 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1794956400.0
  3. ^ "NumPy Sourceforge Files" . Retrieved 2008-03-24 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1206313200.0
  4. ^ "History_of_SciPy - SciPy wiki dump" . scipy.github.io . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1794956400.0
  5. ^ "NumPy 1.5.0 Release Notes" . Retrieved 2011-04-29 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1304031600.0
  6. ^ "PyPy Status Blog: NumPy funding and status update" . Retrieved 2011-12-22 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1324508400.0
  7. ^ "NumPyPy Status" . Retrieved 2023-12-19 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1702940400.0
  8. ^ The SciPy Community. "NumPy for Matlab users" . Retrieved 2 February 2017 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1794956400.0
  9. ^ "OpenCV: Introduction to OpenCV-Python Tutorials" . docs.opencv.org . Retrieved 2026-03-04 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1772578800.0
  10. ^ "numpy release notes" . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1794956400.0
  11. ^ McKinney, Wes (2014). "NumPy Basics: Arrays and Vectorized Computation". Python for Data Analysis (First Edition, Third release ed.). O'Reilly. p. 79. ISBN 978-1-449-31979-3 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1794956400.0
  12. ^ Francesc Alted. "numexpr" . GitHub . Retrieved 8 March 2014 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1794956400.0
  13. ^ "Numba" . numba.pydata.org . Retrieved 8 March 2014 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1794956400.0
  14. ^ Documentationː jax.readthedocs.io Wikipedia revision 1359732874, retrieved 2026-11-18 · 1794956400.0
  15. ^ Shohei Hido - CuPy: A NumPy-compatible Library for GPU - PyCon 2018 , archived from the original on 2021-12-21 , retrieved 2021-05-11 Wikipedia revision 1359732874, retrieved 2026-11-18 · 1620687600.0
  16. ^ Entschev, Peter Andreas (2019-07-23). "Single-GPU CuPy Speedups" . Medium . Retrieved 2021-05-11 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1620687600.0
  17. ^ "NumPy: the absolute basics for beginners § How to import NumPy" . NumPy Manual . v2.3. Archived from the original on 2025-08-28 . Retrieved 1 September 2025 . After installing NumPy, it may be imported into Python code like: 'import numpy as np'. This widespread convention allows access to NumPy features [...] Wikipedia revision 1359732874, retrieved 2026-11-18 · 1794956400.0
  18. ^ "F2PY docs from NumPy" . NumPy . Retrieved 18 April 2022 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1794956400.0
  19. ^ Worthey, Guy (3 January 2022). "A python vs. Fortran smackdown" . Guy Worthey . Retrieved 18 April 2022 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1794956400.0
  20. ^ Shell, Scott. "Writing fast Fortran routines for Python" (PDF) . UCSB Engineering Department . University of California, Santa Barbara . Retrieved 18 April 2022 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1794956400.0
  21. ^ "NumFOCUS Sponsored Projects" . NumFOCUS . Retrieved 2021-10-25 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1635116400.0
  22. ^ "Indexing — NumPy v1.20 Manual" . numpy.org . Retrieved 2021-04-06 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1617663600.0
  23. ^ a b Charles R Harris; Millman, Kenneth Jarrod; van der Walt, Stéfan Johann; et al. (2020). "Array programming with NumPy" (PDF) . Nature . 585 (7825): 357– 362. arXiv : 2006.10256 . Bibcode : 2020Natur.585..357H . doi : 10.1038/s41586-020-2649-2 . PMC 7759461 . PMID 32939066 . Wikidata Q99413970 . {{ Cite Q }} : Missing first/last names in Wikidata for Charles R Harris ( help ) Wikipedia revision 1359732874, retrieved 2026-11-18 · 1794956400.0
  24. ^ Travis E. Oliphant (7 December 2006). Guide to NumPy . Retrieved 2 February 2017 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1794956400.0
  25. ^ a b c d van der Walt, Stéfan; Colbert, S. Chris; Varoquaux, Gaël (2011). "The NumPy array: a structure for efficient numerical computation". Computing in Science and Engineering . 13 (2). IEEE: 22. arXiv : 1102.1523 . Bibcode : 2011CSE....13b..22V . doi : 10.1109/MCSE.2011.37 . S2CID 16907816 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1794956400.0
  26. ^ Travis Oliphant (2007). "Python for Scientific Computing" (PDF) . Computing in Science and Engineering . Archived from the original (PDF) on 2013-10-14 . Retrieved 2013-10-12 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1381532400.0
  27. ^ a b c Millman, K. Jarrod; Aivazis, Michael (2011). "Python for Scientists and Engineers" . Computing in Science and Engineering . 13 (2): 9– 12. Bibcode : 2011CSE....13b...9M . doi : 10.1109/MCSE.2011.36 . Archived from the original on 2019-02-19 . Retrieved 2014-07-07 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1404687600.0
  28. ^ a b c d David Ascher; Paul F. Dubois; Konrad Hinsen; Jim Hugunin; Travis Oliphant (1999). "Numerical Python" (PDF) . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1794956400.0
  29. ^ "NumPy — NumPy" . numpy.org . NumPy developers. Wikipedia revision 1359732874, retrieved 2026-11-18 · 1794956400.0
  30. ^ "Release 2.5.5" . 15 November 2026 . Retrieved 16 November 2026 . Wikipedia revision 1359732874, retrieved 2026-11-18 · 1794956400.0
  31. NumPy. https://en.wikipedia.org/w/index.php?oldid=1359732874 · 1795438144.7002156
source: e01 Encyclopedia · licence: CC BY-SA 4.0 · page · source revision

Cite this

"NumPy". 1781640479. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1359732874

JSON record · API collection · citation policy