# pydoc > numpy

---
type: CommandReference
command: numpy
mode: pydoc
section: ''
source: pydoc3
---

## Quick Reference

- `import numpy as np` — standard import alias
- `np.array([1, 2, 3])` — create array from list
- `np.zeros((3, 4))` — create array of zeros
- `np.ones((2, 2))` — create array of ones
- `np.arange(10)` — create evenly spaced values
- `a.shape`, `a.dtype` — access array shape and data type
- `a.reshape((3, 3))` — reshape array
- `np.sum(a)`, `np.mean(a)` — aggregate operations
- `a @ b` — matrix multiplication (Python 3.5+)
- `np.linalg.inv(a)` — matrix inverse

## Name

NumPy — fundamental package for scientific computing with Python. Provides an N-dimensional array object (`ndarray`), fast vectorized operations, linear algebra, Fourier transforms, and random number generation.

## Synopsis

NumPy is a Python package. Its primary component is the `ndarray` class, a homogeneous multidimensional array. The package includes subpackages for linear algebra (`linalg`), random number generation (`random`), Fourier transforms (`fft`), polynomial operations (`polynomial`), and testing (`testing`). Typing is supported via `numpy.typing`.

## Options

### Subpackages

- `doc` — topical documentation on broadcasting, indexing, etc.
- `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
- `f2py` — Fortran to Python interface generator
- `distutils` — enhancements to distutils with Fortran compiler support

### Key Functions (selected)

- `array(object, dtype=None, copy=True, order='K', subok=False, ndmin=0)` — create an array
- `zeros(shape, dtype=float, order='C')` — return array of zeros
- `ones(shape, dtype=float, order='C')` — return array of ones
- `full(shape, fill_value, dtype=None, order='C')` — return array filled with fill_value
- `arange([start,] stop[, step,], dtype=None)` — evenly spaced values
- `linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0)` — evenly spaced numbers over interval
- `reshape(a, newshape, order='C')` — give new shape to array without changing data
- `concatenate((a1, a2, ...), axis=0, out=None, dtype=None, casting="same_kind")` — join arrays along axis
- `stack(arrays, axis=0, out=None)` — join arrays along new axis
- `split(ary, indices_or_sections, axis=0)` — split array into sub-arrays
- `dot(a, b, out=None)` — dot product (matrix multiplication for 2-D)
- `matmul(x1, x2, /, out=None, **kwargs)` — matrix product (ufunc, supports broadcasting)
- `transpose(a, axes=None)` — reverse or permute axes
- `sort(a, axis=-1, kind=None, order=None)` — return sorted copy
- `argsort(a, axis=-1, kind=None, order=None)` — return indices that would sort
- `sum(a, axis=None, dtype=None, out=None, keepdims=False, initial=0, where=True)` — sum of elements
- `mean(a, axis=None, dtype=None, out=None, keepdims=False, where=True)` — arithmetic mean
- `std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False, where=True)` — standard deviation
- `var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False, where=True)` — variance
- `min(a, axis=None, out=None, keepdims=False, initial=<no value>, where=True)` — minimum
- `max(a, axis=None, out=None, keepdims=False, initial=<no value>, where=True)` — maximum
- `where(condition, [x, y])` — return elements chosen from x or y depending on condition
- `load(file, mmap_mode=None, allow_pickle=False, fix_imports=True, encoding='ASCII')` — load arrays from .npy/.npz files
- `save(file, arr, allow_pickle=True, fix_imports=True)` — save array to .npy file
- `loadtxt(fname, dtype=float, comments='#', delimiter=None, converters=None, skiprows=0, usecols=None, unpack=False, ndmin=0, encoding='bytes', max_rows=None, like=None)` — load from text file
- `savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', header='', footer='', comments='# ', encoding=None)` — save array to text file

### Key Classes

- `ndarray` — multidimensional homogeneous array
- `dtype` — data type object describing array elements
- `ufunc` — universal functions operating element-wise on arrays
- `matrix` — specialized 2-D array with matrix multiplication operators (deprecated, use `ndarray` instead)
- `memmap` — memory-map to an array stored in binary file
- `recarray` — ndarray that allows field access using attributes
- `poly1d` — one-dimensional polynomial class (old API)
- `broadcast` — broadcasting result object
- `flatiter` — flat iterator over arrays
- `nditer` — efficient multi-dimensional iterator
- `ndenumerate` — multidimensional index iterator
- `ndindex` — N-dimensional iterator to index arrays
- `vectorize` — generalized function class

### Data (constants)

- `np.inf`, `np.nan` — infinity and Not-a-Number
- `np.pi` — 3.141592653589793
- `np.e` — 2.718281828459045
- `np.euler_gamma` — 0.5772156649015329
- `np.newaxis` — alias for `None` used for array indexing

## Examples

python
>>> import numpy as np
>>> a = np.array([[1, 2], [3, 4]])
>>> a
array([[1, 2],
       [3, 4]])
>>> np.sum(a)
10
>>> np.mean(a, axis=1)
array([1.5, 3.5])
>>> a @ a.T
array([[ 5, 11],
       [11, 25]])
## See Also

- [NumPy homepage](https://www.scipy.org/scipylib.html)
- [IPython](https://ipython.org) — advanced Python shell with TAB-completion
- `scipy` — scientific computing library built on NumPy
- `matplotlib` — plotting library
- `numpy.typing` — support for type annotations

## Exit Codes

Not applicable (NumPy is a Python package, not a command-line tool).