NumPy

From Wikipedia, the free encyclopedia
NumPy
Original author(s) Travis Oliphant
Developer(s) Community project
Initial release As Numeric, 1995 (1995); as NumPy, 2006 (2006)
Stable release 1.8.0 / 30 October 2013 (2013-10-30)
Written in Python, C
Operating system Cross-platform
Type Technical computing
License BSD-new license
Website www.numpy.org

NumPy is an extension to the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large library of high-level mathematical functions to operate on these arrays. The ancestor 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 Numarray into Numeric with extensive modifications. NumPy is open source and has many contributors.

Traits

Because Python is currently implemented as an interpreter, mathematical algorithms written in it often run slower than compiled equivalents. NumPy seeks to address this problem for numerical algorithms by providing multidimensional arrays and functions and operators that operate efficiently on arrays. Thus any algorithm that can be expressed primarily as operations on arrays and matrices can run almost as quickly as the equivalent C code.[1]

Using NumPy in Python gives functionality comparable to MATLAB since they are both interpreted, and they both allow the user to write fast programs as long as most operations work on arrays or matrices instead of scalars. In comparison, MATLAB boasts a large number of additional toolboxes, notably Simulink; whereas NumPy is intrinsically integrated with Python, a more modern, complete, and open source programming language. Moreover complementary Python packages are available; SciPy is a library that adds more MATLAB-like functionality and Matplotlib is a plotting package that provides MATLAB-like plotting functionality. Internally, both MATLAB and NumPy rely on BLAS and LAPACK for efficient linear algebra computations.

The ndarray data structure

The core functionality of NumPy is its "ndarray", for n-dimensional array, data structure. These arrays are strided views on memory.[2] In contrast to Python's built-in list data structure (which, despite the name, is a dynamic array), these arrays are homogeneously typed: all elements of a single array must be of the same type.

Inside C/C++/Cython extensions to the CPython, and natively in the PyPy interpreter (Python implementations that support NumPy), ndarrays may be constructed from arbitrary memory buffers. NumPy has built-in support for memory-mapped ndarrays.[2]

Routines

The following routines (grouped by functionality) are provided by NumPy :

  1. Array creation routines
  2. Array Manipulation routines
  3. Binary operations
  4. String Operations
  5. C-Type foreign function interface
  6. Date-time support functions
  7. Data type routines
  8. Floating point error handling
  9. Discrete fourier transform
  10. Financial functions
  11. Functional programming
  12. Indexing routines
  13. Input and output
  14. Linear Algebra
  15. Logic Functions
  16. Masked array operations
  17. Mathematical functions
  18. Matrix library
  19. Padding arrays
  20. Polynomials
  21. Random sampling
  22. Set routines
  23. Sorting, searching and counting
  24. Statistics
  25. Test support
  26. Asserts

Example

The following is a simple example of how to do interactive array manipulations and plot a graph with NumPy and Matplotlib.

>>> import numpy as np
>>> import matplotlib.pyplot as mpl
>>> x = np.linspace(0, 2 * np.pi, 100)
>>> y = np.sin(x)
>>> mpl.plot(x, y)
>>> mpl.show()

History

NumPy is based on two earlier Python array packages. The first, variously called Numeric, Numerical Python extensions or NumPy,[2][3] which is reasonably complete and stable, remains available, but is now obsolete. It was originally written in 1995[2] largely by Jim Hugunin, then a graduate student at MIT.[3]:10 When Hugunin joined CNRI to work on JPython, Paul Dubois of LLNL took over as maintainer.[3]:10 Other early contributors include David Ascher, Konrad Hinsen and Travis Oliphant.[3]:10

The other package, Numarray, was written as a more flexible replacement for Numeric.[2] It is also deprecated.[4] Numarray had faster operations for large arrays, but was slower than Numeric on small ones,[citation needed] so for a time both packages were used for different use cases. The last version of Numeric v24.2 was released on 11 November 2005 and numarray v1.5.2 was released on 24 August 2006.[5]

There was a desire to get Numeric into the Python standard library, but Guido van Rossum (the author of Python) was quite clear that the code was not maintainable in its state then.[citation needed]

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[2] 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.

While the source code is freely available and it contains significant documentation, there is also an extensive official Guide to NumPy.[6] The documentation is built around a unified docstring standard.[7]

The release version 1.5.1 of NumPy is compatible with Python versions 2.42.7 and 3.13.2. Support for Python 3 was added in 1.5.0.[8] In 2011, PyPy started development on an implementation of the numpy API for PyPy.[9] It is not yet fully compatible with NumPy.[10]

Video sources

There are several videos recorded in the seminars and the conferences. These videos may help beginners learn how NumPy works. 2009 SciPy meeting had several sessions on SciPy and NumPy.[11]

See also

References

  1. "SciPy PerformancePython". Retrieved 2006-06-25. 
  2. 2.0 2.1 2.2 2.3 2.4 2.5 Stéfan van der Walt, S. Chris Colbert and Gaël Varoquaux (2011). "The NumPy array: a structure for efficient numerical computation". Computing in Science and Engineering (IEEE). 
  3. 3.0 3.1 3.2 3.3 David Ascher; Paul F. Dubois; Konrad Hinsen; Jim Hugunin; Travis Oliphant (1999). "Numerical Python". 
  4. "Numarray Homepage". Retrieved 2006-06-24. 
  5. "NumPy Sourceforge Files". Retrieved 2008-03-24. 
  6. Oliphant, Travis E. (2006-12-07). Guide to NumPy (PDF). 
  7. "NumPy Docstring Standard". Retrieved 2009-11-01. 
  8. "NumPy 1.5.0 Release Notes". Retrieved 2011-04-29. 
  9. "PyPy Status Blog: Numpy funding and status update". Retrieved 2011-12-22. 
  10. "NumPyPy Status". Retrieved 2013-10-14. 
  11. "8th Annual Python in Science Conference". Retrieved 2009-10-04. 

Further reading

  • Bressert, Eli (2012). Scipy and Numpy: An Overview for Developers. O'Reilly Media. ISBN 978-1-4493-0546-8. 

External links

This article is issued from Wikipedia. The text is available under the Creative Commons Attribution/Share Alike; additional terms may apply for the media files.