- Provides
- An array object of arbitrary homogeneous items
- Fast mathematical operations over arrays
- Linear Algebra, Fourier Transforms, Random Number Generation
How to use the documentation
Documentation is available in two forms: docstrings provided with the code, and a loose standing reference guide, available from the NumPy homepage.
We recommend exploring the docstrings using IPython, an advanced Python shell with TAB-completion and introspection capabilities. See below for further instructions.
The docstring examples assume that numpy
has been imported as np:
>>> import numpy as np
Code snippets are indicated by three greater-than signs:
>>> x = 42 >>> x = x + 1
Use the built-in help function to view a function's docstring:
>>> help(np.sort) ... # doctest: +SKIP
For some objects, np.info(obj) may provide additional help. This is particularly true if you see the line "Help on ufunc object:" at the top of the help() page. Ufuncs are implemented in C, not Python, for speed. The native Python help() does not know how to view their help, but our np.info() function does.
To search for documents containing a keyword, do:
>>> np.lookfor('keyword') ... # doctest: +SKIP
General-purpose documents like a glossary and help on the basic concepts of numpy are available under the doc sub-module:
>>> from numpy import doc >>> help(doc) ... # doctest: +SKIP
Available subpackages
- lib
- Basic functions used by several sub-packages.
- random
- Core Random Tools
- linalg
- Core Linear Algebra Tools
- fft
- Core FFT routines
- polynomial
- Polynomial tools
- testing
- NumPy testing tools
- distutils
- Enhancements to distutils with support for Fortran compilers support and more.
Utilities
- test
- Run numpy unittests
- show_config
- Show numpy build configuration
- dual
- Overwrite certain functions with high-performance SciPy tools.
Note:
numpy.dual
is deprecated. Use the functions from NumPy or Scipy directly instead of importing them fromnumpy.dual
. - matlib
- Make everything matrices.
- __version__
- NumPy version string
Viewing documentation using IPython
Start IPython and import numpy
usually under the alias np: import
numpy as np
. Then, directly past or use the %cpaste magic to paste
examples into the shell. To see which functions are available in numpy
,
type np.<TAB> (where <TAB> refers to the TAB key), or use
np.*cos*?<ENTER> (where <ENTER> refers to the ENTER key) to narrow
down the list. To view the docstring for a function, use
np.cos?<ENTER> (to view the docstring) and np.cos??<ENTER> (to view
the source code).
Copies vs. in-place operation
Most of the functions in numpy
return a copy of the array argument
(e.g., np.sort
). In-place versions of these functions are often
available as array methods, i.e. x = np.array([1,2,3]); x.sort().
Exceptions to this rule are documented.
Package | array |
A NumPy sub-namespace that conforms to the Python array API standard. |
Package | compat |
Compatibility module. |
Module | conftest |
Pytest configuration and fixtures for the Numpy test suite. |
Package | core |
Contains the core of NumPy: ndarray, ufuncs, dtypes, etc. |
Module | ctypeslib |
Load a C library. |
Package | distutils |
An enhanced distutils, providing support for Fortran compilers, for BLAS, LAPACK and other common libraries for numerical computing, and more. |
Package | doc |
No package docstring; 0/2 variable, 2/2 modules documented |
Module | dual |
Deprecated since version 1.20. |
Package | f2py |
Fortran to Python Interface Generator. |
Package | fft |
The SciPy module scipy.fft is a more comprehensive superset of numpy.fft, which includes only a basic set of routines. |
Package | lib |
Note: almost all functions in the numpy.lib namespace are also present in the main numpy namespace. Please use the functions as np.<funcname> where possible. |
Package | linalg |
The NumPy linear algebra functions rely on BLAS and LAPACK to provide efficient low level implementations of standard linear algebra algorithms. Those libraries may be provided by NumPy itself using C versions of a subset of their reference implementations but, when possible, highly optimized libraries that take advantage of specialized processor functionality are preferred... |
Package | ma |
Arrays sometimes contain invalid or missing data. When doing operations on such arrays, we wish to suppress invalid values, which is the purpose masked arrays fulfill (an example of typical use is given below). |
Module | matlib |
No module docstring; 8/8 functions documented |
Package | matrixlib |
Sub-package containing the matrix class and related functions. |
Package | polynomial |
A sub-package for efficiently dealing with polynomials. |
Package | random |
Use default_rng() to create a Generator and call its methods. |
Module | setup |
Undocumented |
Package | testing |
Common test support for all numpy test scripts. |
Package | tests |
No package docstring; 3/9 modules documented |
Package | typing |
New in version 1.20. |
Module | version |
Undocumented |
Module | _distributor |
Distributor init file |
Module | _globals |
Module defining global singleton classes. |
Package | _pyinstaller |
No package docstring; 2/3 modules documented |
Module | _pytesttester |
Pytest test running. |
Package | _typing |
Private counterpart of numpy.typing. |
Module | _version |
Undocumented |