This appendix contains a list of useful NumPy functions and their descriptions.
numpy.apply_along_axis
(func1d, axis, arr, *args
): Applies the function func1d
along an axis on 1D slices of arr
.numpy.arange([start,] stop[, step,], dtype=None)
: Creates a NumPy array with evenly spaced values within a specified range.numpy.argsort(a, axis=-1, kind='quicksort', order=None)
: Returns the indices that would sort the input array.numpy.argmax(a, axis=None)
: Returns the indices of the maximum values along an axis.numpy.argmin(a, axis=None)
: Returns the indices of the minimum values along an axis.numpy.argwhere(a)
: Finds the indices of non-zero elements.numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
: Creates a NumPy array from an array-like sequence, such as a Python list.numpy.testing.assert_allclose((actual, desired, rtol=1e-07, atol=0, err_msg='', verbose=True)
: Raises an error if two objects are unequal up to a specified precision.numpy.testing.assert_almost_equal()
: Raises an exception if two numbers are not equal up to a specified precision.numpy.testing.assert_approx_equal()
: Raises an exception if two numbers are not equal up to a certain significance.numpy.testing.assert_array_almost_equal()
: Raises an exception if two arrays are not equal up to a specified precision.numpy.testing.assert_array_almost_equal_nulp(x, y, nulp=1)
: Compares arrays to their unit of least precision (ULP).numpy.testing.assert_array_equal()
: Raises an exception if two arrays are not equal.numpy.testing.assert_array_less()
: Raises an exception if two arrays do not have the same shape, and the elements of the first array are strictly less than the elements of the second array.numpy.testing.assert_array_max_ulp(a, b, maxulp=1, dtype=None)
: Determines whether the array elements differ by, at most, a specified number of ULP.numpy.testing.assert_equal()
: Tests whether two NumPy arrays are equal.numpy.testing.assert_raises()
: Fails if a specified exception is not raised by a callable invoked with defined arguments.numpy.testing.assert_string_equal()
: Asserts that two strings are equal.numpy.testing.assert_warns()
: Fails if a specified warning is not thrown.numpy.bartlett(M)
: Returns the Bartlett window with M
points. This window is similar to a triangular window.numpy.random.binomial(n, p, size=None)
: Draws random samples from the binomial distribution.numpy.bitwise_and(x1, x2[, out])
: Calculates the bit-wise AND
of arrays.numpy.bitwise_xor(x1, x2[, out])
: Calculates the bit-wise XOR
of arrays.numpy.blackman(M)
: Returns a Blackman window with M
points, which is close to optimal and a little bit worse than a Kaiser window.numpy.column_stack(tup)
: Stacks 1D arrays provided as a tuple column wise.numpy.concatenate ((a1, a2, ...), axis=0)
: Concatenates a sequence of arrays.numpy.convolve(a, v, mode='full')
: Computes the linear convolution of 1D arrays.numpy.dot(a, b, out=None)
: Calculates the dot product of two arrays.numpy.diff(a, n=1, axis=-1)
: Computes the nth
difference for a given axis.numpy.dsplit(ary, indices_or_sections)
: Splits an array into subarrays along the third axis.numpy.dstack(tup)
: Stacks arrays given as a tuple along the third axis.numpy.eye(N, M=None, k=0, dtype=<type 'float'>)
: Returns the identity matrix.numpy.extract(condition, arr)
: Selects elements of an array using a condition.numpy.fft.fftshift(x, axes=None)
: Shifts the zero-frequency component of a signal to the center of the spectrum.numpy.hamming(M)
: Returns the Hamming window with M
points.numpy.hanning(M)
: Returns the Hanning window with M
points.numpy.hstack(tup)
: Stacks arrays given as a tuple horizontally.numpy.isreal(x)
: Returns a Boolean array, where True
corresponds to an element of the input array, which is a real number (as opposed to a complex number).numpy.kaiser(M, beta)
: Returns a Kaiser window with M
points for a given beta
parameter.numpy.load(file, mmap_mode=None)
: Loads NumPy arrays or pickled objects from .npy
, .npz
or pickles. A memory-mapped array is stored in the filesystem and doesn't have to be completely loaded in memory. This is especially useful for large arrays.numpy.loadtxt(fname, dtype=<type 'float'>, comments='#', delimiter=None, converters=None, skiprows=0, usecols=None, unpack=False, ndmin=0)
: Loads data from a text file into a NumPy array.numpy.lexsort (keys, axis=-1)
: Sorts using multiple keys.numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
: Returns evenly spaced numbers over an interval.numpy.max(a, axis=None, out=None, keepdims=False)
: Returns the maximum of an array along an axis.numpy.mean(a, axis=None, dtype=None, out=None, keepdims=False)
: Calculates the arithmetic mean along the given axis.numpy.median(a, axis=None, out=None, overwrite_input=False)
: Calculates the median along the given axis.numpy.meshgrid(*xi, **kwargs)
: Returns coordinate matrices for coordinate vectors. For instance:In: numpy.meshgrid([1, 2], [3, 4]) Out: [array([[1, 2], [1, 2]]), array([[3, 3], [4, 4]])]
numpy.min(a, axis=None, out=None, keepdims=False)
: Returns the minimum of an array along an axis.numpy.msort(a)
: Returns a copy of an array sorted along the first axis.numpy.nanargmax(a, axis=None)
: Returns the indices of the maximums given an axis ignoring NaNs.numpy.nanargmin(a, axis=None)
: Returns the indices of the minimums given an axis ignoring NaNs.numpy.nonzero(a)
: Returns indices of non-zero array elements.numpy.ones(shape, dtype=None, order='C')
: Creates a NumPy array of specified shape and data type, containing 1s.numpy.piecewise(x, condlist, funclist, *args, **kw)
: Evaluates a function piecewise.numpy.polyder(p, m=1)
: Differentiates a polynomial to a given order.numpy.polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False)
: Performs a least squares polynomial fit.numpy.polysub(a1, a2)
: Subtracts polynomials.numpy.polyval(p, x)
: Evaluates a polynomial at specified values.numpy.prod(a, axis=None, dtype=None, out=None, keepdims=False)
: Returns the product of array elements over a specified axis.numpy.ravel(a, order='C')
: Flattens an array or returns a copy if necessary.numpy.reshape(a, newshape, order='C')
: Changes the shape of a NumPy array.numpy.row_stack(tup)
: Stacks arrays row wise.numpy.save(file, arr)
: Saves a NumPy array to a file in the NumPy .npy
format.numpy.savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='
', header='', footer='', comments='# ')
: Saves a NumPy array to a text file.numpy.sinc(a)
: Computes the sinc
function.numpy.sort_complex(a)
: Sorts array elements with the real part first, then followed by the imaginary part.numpy.split(a, indices_or_sections, axis=0)
: Splits an array into subarrays.numpy.std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False)
: Returns the standard deviation along the given axis.numpy.take(a, indices, axis=None, out=None, mode='raise')
: Selects elements from an array using specified indices.numpy.vsplit(a, indices_or_sections)
: Splits an array into subarrays vertically.numpy.vstack(tup)
: Stacks arrays vertically.numpy.where(condition, [x, y])
: Selects array elements from input arrays based on a Boolean condition.numpy.zeros(shape, dtype=float, order='C')
: Creates a NumPy array of specified shape and data type, containing zeros.