Create a memory-map to an array stored in a binary file on disk.
Memory-mapped files are used for accessing small segments of large files on disk, without reading the entire file into memory. NumPy’s memmap’s are array-like objects. This differs from Python’s mmap module, which uses file-like objects.
This subclass of ndarray has some unpleasant interactions with some operations, because it doesn’t quite fit properly as a subclass. An alternative to using this subclass is to create the mmap object yourself, then create an ndarray with ndarray.__new__ directly, passing the object created in its ‘buffer=’ parameter.
This class may at some point be turned into a factory function which returns a view into an mmap buffer.
Flush the memmap instance to write the changes to the file. Currently there is no API to close the underlying mmap. It is tricky to ensure the resource is actually closed, since it may be shared between different memmap instances.
The file name or file object to be used as the array data buffer.
The data-type used to interpret the file contents. Default is uint8.
The file is opened in this mode:
‘r’
Open existing file for reading only.
‘r+’
Open existing file for reading and writing.
‘w+’
Create or overwrite existing file for reading and writing.
‘c’
Copy-on-write: assignments affect data in memory, but changes are not saved to disk. The file on disk is read-only.
Default is ‘r+’.
In the file, array data starts at this offset. Since offset is measured in bytes, it should normally be a multiple of the byte-size of dtype. When mode != 'r', even positive offsets beyond end of file are valid; The file will be extended to accommodate the additional data. By default, memmap will start at the beginning of the file, even if filename is a file pointer fp and fp.tell() != 0.
The desired shape of the array. If mode == 'r' and the number of remaining bytes after offset is not a multiple of the byte-size of dtype, you must specify shape. By default, the returned array will be 1-D with the number of elements determined by file size and data-type.
Specify the order of the ndarray memory layout: row-major, C-style or column-major, Fortran-style. This only has an effect if the shape is greater than 1-D. The default order is ‘C’.
See also
Create or load a memory-mapped .npy file.
The memmap object can be used anywhere an ndarray is accepted. Given a memmap fp, isinstance(fp, numpy.ndarray) returns True.
Memory-mapped files cannot be larger than 2GB on 32-bit systems.
When a memmap causes a file to be created or extended beyond its current size in the filesystem, the contents of the new part are unspecified. On systems with POSIX filesystem semantics, the extended part will be filled with zero bytes.
This example uses a temporary file so that doctest doesn’t write files to your directory. You would use a ‘normal’ filename.
Create a memmap with dtype and shape that matches our data:
Write data to memmap array:
Flushes memory changes to disk in order to read them back
Load the memmap and verify data was stored:
Read-only memmap:
Copy-on-write memmap:
It’s possible to assign to copy-on-write array, but values are only written into the memory copy of the array, and not written to disk:
File on disk is unchanged:
Offset into a memmap:
Path to the mapped file.
Offset position in the file.
File mode.
flush()
Write any changes in the array to the file on disk.


Return coordinate matrices from coordinate vectors.
Make N-D coordinate arrays for vectorized evaluations of N-D scalar/vector fields over N-D grids, given one-dimensional coordinate arrays x1, x2,…, xn.
Changed in version 1.9: 1-D and 0-D cases are allowed.
1-D arrays representing the coordinates of a grid.
Cartesian (‘xy’, default) or matrix (‘ij’) indexing of output. See Notes for more details.
New in version 1.7.0.
If True the shape of the returned coordinate array for dimension i is reduced from (N1, ..., Ni, ... Nn) to (1, ..., 1, Ni, 1, ..., 1). These sparse coordinate grids are intended to be use with Broadcasting. When all coordinates are used in an expression, broadcasting still leads to a fully-dimensonal result array.
Default is False.
New in version 1.7.0.
If False, a view into the original arrays are returned in order to conserve memory. Default is True. Please note that sparse=False, copy=False will likely return non-contiguous arrays. Furthermore, more than one element of a broadcast array may refer to a single memory location. If you need to write to the arrays, make copies first.
New in version 1.7.0.
For vectors x1, x2,…, ‘xn’ with lengths Ni=len(xi) , return (N1, N2, N3,...Nn) shaped arrays if indexing=’ij’ or (N2, N1, N3,...Nn) shaped arrays if indexing=’xy’ with the elements of xi repeated to fill the matrix along the first dimension for x1, the second for x2 and so on.
See also
Construct a multi-dimensional “meshgrid” using indexing notation.
Construct an open multi-dimensional “meshgrid” using indexing notation.
This function supports both indexing conventions through the indexing keyword argument. Giving the string ‘ij’ returns a meshgrid with matrix indexing, while ‘xy’ returns a meshgrid with Cartesian indexing. In the 2-D case with inputs of length M and N, the outputs are of shape (N, M) for ‘xy’ indexing and (M, N) for ‘ij’ indexing. In the 3-D case with inputs of length M, N and P, outputs are of shape (N, M, P) for ‘xy’ indexing and (M, N, P) for ‘ij’ indexing. The difference is illustrated by the following code snippet:
In the 1-D and 0-D case, the indexing and sparse keywords have no effect.
meshgrid is very useful to evaluate functions on a grid. If the function depends on all coordinates, you can use the parameter sparse=True to save memory and computation time.


nd_grid instance which returns a dense multi-dimensional “meshgrid”.
An instance of numpy.lib.index_tricks.nd_grid which returns an dense (or fleshed out) mesh-grid when indexed, so that each returned argument has the same shape. The dimensions and number of the output arrays are equal to the number of indexing dimensions. If the step length is not a complex number, then the stop is not inclusive.
However, if the step length is a complex number (e.g. 5j), then the integer part of its magnitude is interpreted as specifying the number of points to create between the start and stop values, where the stop value is inclusive.
See also
class of ogrid and mgrid objects
like mgrid but returns open (not fleshed out) mesh grids
array concatenator


For scalar a, returns the data type with the smallest size and smallest scalar kind which can hold its value. For non-scalar array a, returns the vector’s dtype unmodified.
Floating point values are not demoted to integers, and complex values are not demoted to floats.
The value whose minimal data type is to be found.
The minimal data type.
See also
New in version 1.6.0.


Element-wise minimum of array elements.
Compare two arrays and returns a new array containing the element-wise minima. If one of the elements being compared is a NaN, then that element is returned. If both elements are NaNs then the first is returned. The latter distinction is important for complex NaNs, which are defined as at least one of the real or imaginary parts being a NaN. The net effect is that NaNs are propagated.
The arrays holding the elements to be compared. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).
A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.
This condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.
For other keyword-only arguments, see the ufunc docs.
The minimum of x1 and x2, element-wise. This is a scalar if both x1 and x2 are scalars.
See also
Element-wise maximum of two arrays, propagates NaNs.
Element-wise minimum of two arrays, ignores NaNs.
The minimum value of an array along a given axis, propagates NaNs.
The minimum value of an array along a given axis, ignores NaNs.
The minimum is equivalent to np.where(x1 <= x2, x1, x2) when neither x1 nor x2 are NaNs, but it is faster and does proper broadcasting.


Return the character for the minimum-size type to which given types can be safely cast.
The returned type character must represent the smallest size dtype such that an array of the returned type can handle the data from an array of all types in typechars (or if typechars is an array, then its dtype.char).
If a list of strings, each string should represent a dtype. If array_like, the character representation of the array dtype is used.
The set of characters that the returned character is chosen from. The default set is ‘GDFgdf’.
The default character, this is returned if none of the characters in typechars matches a character in typeset.
The character representing the minimum-size type that was found.
See also


Returns the element-wise remainder of division.
Computes the remainder complementary to the floor_divide function. It is equivalent to the Python modulus operator``x1 % x2`` and has the same sign as the divisor x2. The MATLAB function equivalent to np.remainder is mod.
Warning
This should not be confused with:
Dividend array.
Divisor array. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).
A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.
This condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.
For other keyword-only arguments, see the ufunc docs.
The element-wise remainder of the quotient floor_divide(x1, x2). This is a scalar if both x1 and x2 are scalars.
See also
Equivalent of Python // operator.
Simultaneous floor division and remainder.
Equivalent of the MATLAB rem function.
Returns 0 when x2 is 0 and both x1 and x2 are (arrays of) integers. mod is an alias of remainder.
The % operator can be used as a shorthand for np.remainder on ndarrays.


Return the fractional and integral parts of an array, element-wise.
The fractional and integral parts are negative if the given number is negative.
Input array.
A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.
This condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.
For other keyword-only arguments, see the ufunc docs.
Fractional part of x. This is a scalar if x is a scalar.
Integral part of x. This is a scalar if x is a scalar.
See also
divmod(x, 1) is equivalent to modf with the return values switched, except it always has a positive remainder.
For integer input the return values are floats.


Move axes of an array to new positions.
Other axes remain in their original order.
New in version 1.11.0.
The array whose axes should be reordered.
Original positions of the axes to move. These must be unique.
Destination positions for each of the original axes. These must also be unique.
Array with moved axes. This array is a view of the input array.
See also
Permute the dimensions of an array.
Interchange two axes of an array.
These all achieve the same result:


Return a copy of an array sorted along the first axis.
Array to be sorted.
Array of the same type and shape as a.
See also
np.msort(a) is equivalent to np.sort(a, axis=0).


Multiply arguments element-wise.
Input arrays to be multiplied. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).
A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.
This condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.
For other keyword-only arguments, see the ufunc docs.
The product of x1 and x2, element-wise. This is a scalar if both x1 and x2 are scalars.
Equivalent to x1 * x2 in terms of array broadcasting.
The * operator can be used as a shorthand for np.multiply on ndarrays.


IEEE 754 floating point representation of Not a Number (NaN).
NaN and NAN are equivalent definitions of nan. Please use nan instead of NAN.
nan


IEEE 754 floating point representation of Not a Number (NaN).
NaN and NAN are equivalent definitions of nan. Please use nan instead of NaN.
nan


IEEE 754 floating point representation of Not a Number (NaN).
y : A floating point representation of Not a Number.
isnan : Shows which elements are Not a Number.
isfinite : Shows which elements are finite (not one of Not a Number, positive infinity and negative infinity)
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity.
NaN and NAN are aliases of nan.


Replace NaN with zero and infinity with large finite numbers (default behaviour) or with the numbers defined by the user using the nan, posinf and/or neginf keywords.
If x is inexact, NaN is replaced by zero or by the user defined value in nan keyword, infinity is replaced by the largest finite floating point values representable by x.dtype or by the user defined value in posinf keyword and -infinity is replaced by the most negative finite floating point values representable by x.dtype or by the user defined value in neginf keyword.
For complex dtypes, the above is applied to each of the real and imaginary components of x separately.
If x is not inexact, then no replacements are made.
Input data.
Whether to create a copy of x (True) or to replace values in-place (False). The in-place operation only occurs if casting to an array does not require a copy. Default is True.
New in version 1.13.
Value to be used to fill NaN values. If no value is passed then NaN values will be replaced with 0.0.
New in version 1.17.
Value to be used to fill positive infinity values. If no value is passed then positive infinity values will be replaced with a very large number.
New in version 1.17.
Value to be used to fill negative infinity values. If no value is passed then negative infinity values will be replaced with a very small (or negative) number.
New in version 1.17.
x, with the non-finite values replaced. If copy is False, this may be x itself.
See also
Shows which elements are positive or negative infinity.
Shows which elements are negative infinity.
Shows which elements are positive infinity.
Shows which elements are Not a Number (NaN).
Shows which elements are finite (not NaN, not infinity)
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity.


Return the indices of the maximum values in the specified axis ignoring NaNs. For all-NaN slices ValueError is raised. Warning: the results cannot be trusted if a slice contains only NaNs and -Infs.
Input data.
Axis along which to operate. By default flattened input is used.
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype.
New in version 1.22.0.
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the array.
New in version 1.22.0.
An array of indices or a single index value.
See also


Return the indices of the minimum values in the specified axis ignoring NaNs. For all-NaN slices ValueError is raised. Warning: the results cannot be trusted if a slice contains only NaNs and Infs.
Input data.
Axis along which to operate. By default flattened input is used.
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype.
New in version 1.22.0.
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the array.
New in version 1.22.0.
An array of indices or a single index value.
See also


Return the cumulative product of array elements over a given axis treating Not a Numbers (NaNs) as one. The cumulative product does not change when NaNs are encountered and leading NaNs are replaced by ones.
Ones are returned for slices that are all-NaN or empty.
New in version 1.12.0.
Input array.
Axis along which the cumulative product is computed. By default the input is flattened.
Type of the returned array, as well as of the accumulator in which the elements are multiplied. If dtype is not specified, it defaults to the dtype of a, unless a has an integer dtype with a precision less than that of the default platform integer. In that case, the default platform integer is used instead.
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type of the resulting values will be cast if necessary.
A new array holding the result is returned unless out is specified, in which case it is returned.
See also
Cumulative product across array propagating NaNs.
Show which elements are NaN.


Return the cumulative sum of array elements over a given axis treating Not a Numbers (NaNs) as zero. The cumulative sum does not change when NaNs are encountered and leading NaNs are replaced by zeros.
Zeros are returned for slices that are all-NaN or empty.
New in version 1.12.0.
Input array.
Axis along which the cumulative sum is computed. The default (None) is to compute the cumsum over the flattened array.
Type of the returned array and of the accumulator in which the elements are summed. If dtype is not specified, it defaults to the dtype of a, unless a has an integer dtype with a precision less than that of the default platform integer. In that case, the default platform integer is used.
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. See Output type determination for more details.
A new array holding the result is returned unless out is specified, in which it is returned. The result has the same size as a, and the same shape as a if axis is not None or a is a 1-d array.
See also
Cumulative sum across array propagating NaNs.
Show which elements are NaN.


Return the maximum of an array or maximum along an axis, ignoring any NaNs. When all-NaN slices are encountered a RuntimeWarning is raised and NaN is returned for that slice.
Array containing numbers whose maximum is desired. If a is not an array, a conversion is attempted.
Axis or axes along which the maximum is computed. The default is to compute the maximum of the flattened array.
Alternate output array in which to place the result. The default is None; if provided, it must have the same shape as the expected output, but the type will be cast if necessary. See Output type determination for more details.
New in version 1.8.0.
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a.
If the value is anything but the default, then keepdims will be passed through to the max method of sub-classes of ndarray. If the sub-classes methods does not implement keepdims any exceptions will be raised.
New in version 1.8.0.
The minimum value of an output element. Must be present to allow computation on empty slice. See reduce for details.
New in version 1.22.0.
Elements to compare for the maximum. See reduce for details.
New in version 1.22.0.
An array with the same shape as a, with the specified axis removed. If a is a 0-d array, or if axis is None, an ndarray scalar is returned. The same dtype as a is returned.
See also
The minimum value of an array along a given axis, ignoring any NaNs.
The maximum value of an array along a given axis, propagating any NaNs.
Element-wise maximum of two arrays, ignoring any NaNs.
Element-wise maximum of two arrays, propagating any NaNs.
Shows which elements are Not a Number (NaN).
Shows which elements are neither NaN nor infinity.
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity. Positive infinity is treated as a very large number and negative infinity is treated as a very small (i.e. negative) number.
If the input has a integer type the function is equivalent to np.max.
When positive infinity and negative infinity are present:


Compute the arithmetic mean along the specified axis, ignoring NaNs.
Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. float64 intermediate and return values are used for integer inputs.
For all-NaN slices, NaN is returned and a RuntimeWarning is raised.
New in version 1.8.0.
Array containing numbers whose mean is desired. If a is not an array, a conversion is attempted.
Axis or axes along which the means are computed. The default is to compute the mean of the flattened array.
Type to use in computing the mean. For integer inputs, the default is float64; for inexact inputs, it is the same as the input dtype.
Alternate output array in which to place the result. The default is None; if provided, it must have the same shape as the expected output, but the type will be cast if necessary. See Output type determination for more details.
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a.
If the value is anything but the default, then keepdims will be passed through to the mean or sum methods of sub-classes of ndarray. If the sub-classes methods does not implement keepdims any exceptions will be raised.
Elements to include in the mean. See reduce for details.
New in version 1.22.0.
If out=None, returns a new array containing the mean values, otherwise a reference to the output array is returned. Nan is returned for slices that contain only NaNs.
See also
Weighted average
Arithmetic mean taken while not ignoring NaNs
The arithmetic mean is the sum of the non-NaN elements along the axis divided by the number of non-NaN elements.
Note that for floating-point input, the mean is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32. Specifying a higher-precision accumulator using the dtype keyword can alleviate this issue.


Compute the median along the specified axis, while ignoring NaNs.
Returns the median of the array elements.
New in version 1.9.0.
Input array or object that can be converted to an array.
Axis or axes along which the medians are computed. The default is to compute the median along a flattened version of the array. A sequence of axes is supported since version 1.9.0.
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output, but the type (of the output) will be cast if necessary.
If True, then allow use of memory of input array a for calculations. The input array will be modified by the call to median. This will save memory when you do not need to preserve the contents of the input array. Treat the input as undefined, but it will probably be fully or partially sorted. Default is False. If overwrite_input is True and a is not already an ndarray, an error will be raised.
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a.
If this is anything but the default value it will be passed through (in the special case of an empty array) to the mean function of the underlying array. If the array is a sub-class and mean does not have the kwarg keepdims this will raise a RuntimeError.
A new array holding the result. If the input contains integers or floats smaller than float64, then the output data-type is np.float64. Otherwise, the data-type of the output is the same as that of the input. If out is specified, that array is returned instead.
See also
Given a vector V of length N, the median of V is the middle value of a sorted copy of V, V_sorted - i.e., V_sorted[(N-1)/2], when N is odd and the average of the two middle values of V_sorted when N is even.


Return minimum of an array or minimum along an axis, ignoring any NaNs. When all-NaN slices are encountered a RuntimeWarning is raised and Nan is returned for that slice.
Array containing numbers whose minimum is desired. If a is not an array, a conversion is attempted.
Axis or axes along which the minimum is computed. The default is to compute the minimum of the flattened array.
Alternate output array in which to place the result. The default is None; if provided, it must have the same shape as the expected output, but the type will be cast if necessary. See Output type determination for more details.
New in version 1.8.0.
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a.
If the value is anything but the default, then keepdims will be passed through to the min method of sub-classes of ndarray. If the sub-classes methods does not implement keepdims any exceptions will be raised.
New in version 1.8.0.
The maximum value of an output element. Must be present to allow computation on empty slice. See reduce for details.
New in version 1.22.0.
Elements to compare for the minimum. See reduce for details.
New in version 1.22.0.
An array with the same shape as a, with the specified axis removed. If a is a 0-d array, or if axis is None, an ndarray scalar is returned. The same dtype as a is returned.
See also
The maximum value of an array along a given axis, ignoring any NaNs.
The minimum value of an array along a given axis, propagating any NaNs.
Element-wise minimum of two arrays, ignoring any NaNs.
Element-wise minimum of two arrays, propagating any NaNs.
Shows which elements are Not a Number (NaN).
Shows which elements are neither NaN nor infinity.
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity. Positive infinity is treated as a very large number and negative infinity is treated as a very small (i.e. negative) number.
If the input has a integer type the function is equivalent to np.min.
When positive infinity and negative infinity are present:


Compute the qth percentile of the data along the specified axis, while ignoring nan values.
Returns the qth percentile(s) of the array elements.
New in version 1.9.0.
Input array or object that can be converted to an array, containing nan values to be ignored.
Percentile or sequence of percentiles to compute, which must be between 0 and 100 inclusive.
Axis or axes along which the percentiles are computed. The default is to compute the percentile(s) along a flattened version of the array.
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output, but the type (of the output) will be cast if necessary.
If True, then allow the input array a to be modified by intermediate calculations, to save memory. In this case, the contents of the input a after this function completes is undefined.
This parameter specifies the method to use for estimating the percentile. There are many different methods, some unique to NumPy. See the notes for explanation. The options sorted by their R type as summarized in the H&F paper [1] are:
The first three methods are discontiuous. NumPy further defines the following discontinuous variations of the default ‘linear’ (7.) option:
Changed in version 1.22.0: This argument was previously called “interpolation” and only offered the “linear” default and last four options.
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original array a.
If this is anything but the default value it will be passed through (in the special case of an empty array) to the mean function of the underlying array. If the array is a sub-class and mean does not have the kwarg keepdims this will raise a RuntimeError.
Deprecated name for the method keyword argument.
Deprecated since version 1.22.0.
If q is a single percentile and axis=None, then the result is a scalar. If multiple percentiles are given, first axis of the result corresponds to the percentiles. The other axes are the axes that remain after the reduction of a. If the input contains integers or floats smaller than float64, the output data-type is float64. Otherwise, the output data-type is the same as that of the input. If out is specified, that array is returned instead.
See also
equivalent to nanpercentile(..., 50)
equivalent to nanpercentile, except q in range [0, 1].
For more information please see numpy.percentile
R. J. Hyndman and Y. Fan, “Sample quantiles in statistical packages,” The American Statistician, 50(4), pp. 361-365, 1996


Return the product of array elements over a given axis treating Not a Numbers (NaNs) as ones.
One is returned for slices that are all-NaN or empty.
New in version 1.10.0.
Array containing numbers whose product is desired. If a is not an array, a conversion is attempted.
Axis or axes along which the product is computed. The default is to compute the product of the flattened array.
The type of the returned array and of the accumulator in which the elements are summed. By default, the dtype of a is used. An exception is when a has an integer type with less precision than the platform (u)intp. In that case, the default will be either (u)int32 or (u)int64 depending on whether the platform is 32 or 64 bits. For inexact inputs, dtype must be inexact.
Alternate output array in which to place the result. The default is None. If provided, it must have the same shape as the expected output, but the type will be cast if necessary. See Output type determination for more details. The casting of NaN to integer can yield unexpected results.
If True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original arr.
The starting value for this product. See reduce for details.
New in version 1.22.0.
Elements to include in the product. See reduce for details.
New in version 1.22.0.
A new array holding the result is returned unless out is specified, in which case it is returned.
See also
Product across array propagating NaNs.
Show which elements are NaN.


Compute the qth quantile of the data along the specified axis, while ignoring nan values. Returns the qth quantile(s) of the array elements.
New in version 1.15.0.
Input array or object that can be converted to an array, containing nan values to be ignored
Quantile or sequence of quantiles to compute, which must be between 0 and 1 inclusive.
Axis or axes along which the quantiles are computed. The default is to compute the quantile(s) along a flattened version of the array.
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output, but the type (of the output) will be cast if necessary.
If True, then allow the input array a to be modified by intermediate calculations, to save memory. In this case, the contents of the input a after this function completes is undefined.
This parameter specifies the method to use for estimating the quantile. There are many different methods, some unique to NumPy. See the notes for explanation. The options sorted by their R type as summarized in the H&F paper [1] are:
The first three methods are discontiuous. NumPy further defines the following discontinuous variations of the default ‘linear’ (7.) option:
Changed in version 1.22.0: This argument was previously called “interpolation” and only offered the “linear” default and last four options.
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original array a.
If this is anything but the default value it will be passed through (in the special case of an empty array) to the mean function of the underlying array. If the array is a sub-class and mean does not have the kwarg keepdims this will raise a RuntimeError.
Deprecated name for the method keyword argument.
Deprecated since version 1.22.0.
If q is a single percentile and axis=None, then the result is a scalar. If multiple quantiles are given, first axis of the result corresponds to the quantiles. The other axes are the axes that remain after the reduction of a. If the input contains integers or floats smaller than float64, the output data-type is float64. Otherwise, the output data-type is the same as that of the input. If out is specified, that array is returned instead.
See also
equivalent to nanquantile(..., 0.5)
same as nanquantile, but with q in the range [0, 100].
For more information please see numpy.quantile
R. J. Hyndman and Y. Fan, “Sample quantiles in statistical packages,” The American Statistician, 50(4), pp. 361-365, 1996


Compute the standard deviation along the specified axis, while ignoring NaNs.
Returns the standard deviation, a measure of the spread of a distribution, of the non-NaN array elements. The standard deviation is computed for the flattened array by default, otherwise over the specified axis.
For all-NaN slices or slices with zero degrees of freedom, NaN is returned and a RuntimeWarning is raised.
New in version 1.8.0.
Calculate the standard deviation of the non-NaN values.
Axis or axes along which the standard deviation is computed. The default is to compute the standard deviation of the flattened array.
Type to use in computing the standard deviation. For arrays of integer type the default is float64, for arrays of float types it is the same as the array type.
Alternative output array in which to place the result. It must have the same shape as the expected output but the type (of the calculated values) will be cast if necessary.
Means Delta Degrees of Freedom. The divisor used in calculations is N - ddof, where N represents the number of non-NaN elements. By default ddof is zero.
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a.
If this value is anything but the default it is passed through as-is to the relevant functions of the sub-classes. If these functions do not have a keepdims kwarg, a RuntimeError will be raised.
Elements to include in the standard deviation. See reduce for details.
New in version 1.22.0.
If out is None, return a new array containing the standard deviation, otherwise return a reference to the output array. If ddof is >= the number of non-NaN elements in a slice or the slice contains only NaNs, then the result for that slice is NaN.
See also
The standard deviation is the square root of the average of the squared deviations from the mean: std = sqrt(mean(abs(x - x.mean())**2)).
The average squared deviation is normally calculated as x.sum() / N, where N = len(x). If, however, ddof is specified, the divisor N - ddof is used instead. In standard statistical practice, ddof=1 provides an unbiased estimator of the variance of the infinite population. ddof=0 provides a maximum likelihood estimate of the variance for normally distributed variables. The standard deviation computed in this function is the square root of the estimated variance, so even with ddof=1, it will not be an unbiased estimate of the standard deviation per se.
Note that, for complex numbers, std takes the absolute value before squaring, so that the result is always real and nonnegative.
For floating-point input, the std is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32 (see example below). Specifying a higher-accuracy accumulator using the dtype keyword can alleviate this issue.


Return the sum of array elements over a given axis treating Not a Numbers (NaNs) as zero.
In NumPy versions <= 1.9.0 Nan is returned for slices that are all-NaN or empty. In later versions zero is returned.
Array containing numbers whose sum is desired. If a is not an array, a conversion is attempted.
Axis or axes along which the sum is computed. The default is to compute the sum of the flattened array.
The type of the returned array and of the accumulator in which the elements are summed. By default, the dtype of a is used. An exception is when a has an integer type with less precision than the platform (u)intp. In that case, the default will be either (u)int32 or (u)int64 depending on whether the platform is 32 or 64 bits. For inexact inputs, dtype must be inexact.
New in version 1.8.0.
Alternate output array in which to place the result. The default is None. If provided, it must have the same shape as the expected output, but the type will be cast if necessary. See Output type determination for more details. The casting of NaN to integer can yield unexpected results.
New in version 1.8.0.
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a.
If the value is anything but the default, then keepdims will be passed through to the mean or sum methods of sub-classes of ndarray. If the sub-classes methods does not implement keepdims any exceptions will be raised.
New in version 1.8.0.
Starting value for the sum. See reduce for details.
New in version 1.22.0.
Elements to include in the sum. See reduce for details.
New in version 1.22.0.
A new array holding the result is returned unless out is specified, in which it is returned. The result has the same size as a, and the same shape as a if axis is not None or a is a 1-d array.
See also
Sum across array propagating NaNs.
Show which elements are NaN.
Show which elements are not NaN or +/-inf.
If both positive and negative infinity are present, the sum will be Not A Number (NaN).


Compute the variance along the specified axis, while ignoring NaNs.
Returns the variance of the array elements, a measure of the spread of a distribution. The variance is computed for the flattened array by default, otherwise over the specified axis.
For all-NaN slices or slices with zero degrees of freedom, NaN is returned and a RuntimeWarning is raised.
New in version 1.8.0.
Array containing numbers whose variance is desired. If a is not an array, a conversion is attempted.
Axis or axes along which the variance is computed. The default is to compute the variance of the flattened array.
Type to use in computing the variance. For arrays of integer type the default is float64; for arrays of float types it is the same as the array type.
Alternate output array in which to place the result. It must have the same shape as the expected output, but the type is cast if necessary.
“Delta Degrees of Freedom”: the divisor used in the calculation is N - ddof, where N represents the number of non-NaN elements. By default ddof is zero.
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a.
Elements to include in the variance. See reduce for details.
New in version 1.22.0.
If out is None, return a new array containing the variance, otherwise return a reference to the output array. If ddof is >= the number of non-NaN elements in a slice or the slice contains only NaNs, then the result for that slice is NaN.
See also
Standard deviation
Average
Variance while not ignoring NaNs
The variance is the average of the squared deviations from the mean, i.e., var = mean(abs(x - x.mean())**2).
The mean is normally calculated as x.sum() / N, where N = len(x). If, however, ddof is specified, the divisor N - ddof is used instead. In standard statistical practice, ddof=1 provides an unbiased estimator of the variance of a hypothetical infinite population. ddof=0 provides a maximum likelihood estimate of the variance for normally distributed variables.
Note that for complex numbers, the absolute value is taken before squaring, so that the result is always real and nonnegative.
For floating-point input, the variance is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32 (see example below). Specifying a higher-accuracy accumulator using the dtype keyword can alleviate this issue.
For this function to work on sub-classes of ndarray, they must define sum with the kwarg keepdims


An array object represents a multidimensional, homogeneous array of fixed-size items. An associated data-type object describes the format of each element in the array (its byte-order, how many bytes it occupies in memory, whether it is an integer, a floating point number, or something else, etc.)
Arrays should be constructed using array, zeros or empty (refer to the See Also section below). The parameters given here refer to a low-level method (ndarray(…)) for instantiating an array.
For more information, refer to the numpy module and examine the methods and attributes of an array.
Shape of created array.
Any object that can be interpreted as a numpy data type.
Used to fill the array with data.
Offset of array data in buffer.
Strides of data in memory.
Row-major (C-style) or column-major (Fortran-style) order.
See also
Construct an array.
Create an array, each element of which is zero.
Create an array, but leave its allocated memory unchanged (i.e., it contains “garbage”).
Create a data-type.
An ndarray alias generic w.r.t. its dtype.type.
There are two modes of creating an array using __new__:
No __init__ method is needed because the array is fully initialized after the __new__ method.
These examples illustrate the low-level ndarray constructor. Refer to the See Also section above for easier ways of constructing an ndarray.
First mode, buffer is None:
Second mode:
The transposed array.
Python buffer object pointing to the start of the array’s data.
Data-type of the array’s elements.
Information about the memory layout of the array.
A 1-D iterator over the array.
The imaginary part of the array.
The real part of the array.
Number of elements in the array.
Length of one array element in bytes.
Total bytes consumed by the elements of the array.
Number of array dimensions.
Tuple of array dimensions.
Tuple of bytes to step in each dimension when traversing an array.
An object to simplify the interaction of the array with the ctypes module.
Base object if memory is from some other object.
all([axis, out, keepdims, where])
Returns True if all elements evaluate to True.
any([axis, out, keepdims, where])
Returns True if any of the elements of a evaluate to True.
argmax([axis, out])
Return indices of the maximum values along the given axis.
argmin([axis, out])
Return indices of the minimum values along the given axis.
argpartition(kth[, axis, kind, order])
Returns the indices that would partition this array.
argsort([axis, kind, order])
Returns the indices that would sort this array.
astype(dtype[, order, casting, subok, copy])
Copy of the array, cast to a specified type.
byteswap([inplace])
Swap the bytes of the array elements
choose(choices[, out, mode])
Use an index array to construct a new array from a set of choices.
clip([min, max, out])
Return an array whose values are limited to [min, max].
compress(condition[, axis, out])
Return selected slices of this array along given axis.
conj()
Complex-conjugate all elements.
conjugate()
Return the complex conjugate, element-wise.
copy([order])
Return a copy of the array.
cumprod([axis, dtype, out])
Return the cumulative product of the elements along the given axis.
cumsum([axis, dtype, out])
Return the cumulative sum of the elements along the given axis.
diagonal([offset, axis1, axis2])
Return specified diagonals.
dump(file)
Dump a pickle of the array to the specified file.
dumps()
Returns the pickle of the array as a string.
fill(value)
Fill the array with a scalar value.
flatten([order])
Return a copy of the array collapsed into one dimension.
getfield(dtype[, offset])
Returns a field of the given array as a certain type.
item(*args)
Copy an element of an array to a standard Python scalar and return it.
itemset(*args)
Insert scalar into an array (scalar is cast to array's dtype, if possible)
max([axis, out, keepdims, initial, where])
Return the maximum along a given axis.
mean([axis, dtype, out, keepdims, where])
Returns the average of the array elements along given axis.
min([axis, out, keepdims, initial, where])
Return the minimum along a given axis.
newbyteorder([new_order])
Return the array with the same data viewed with a different byte order.
nonzero()
Return the indices of the elements that are non-zero.
partition(kth[, axis, kind, order])
Rearranges the elements in the array in such a way that the value of the element in kth position is in the position it would be in a sorted array.
prod([axis, dtype, out, keepdims, initial, ...])
Return the product of the array elements over the given axis
ptp([axis, out, keepdims])
Peak to peak (maximum - minimum) value along a given axis.
put(indices, values[, mode])
Set a.flat[n] = values[n] for all n in indices.
ravel([order])
Return a flattened array.
repeat(repeats[, axis])
Repeat elements of an array.
reshape(shape[, order])
Returns an array containing the same data with a new shape.
resize(new_shape[, refcheck])
Change shape and size of array in-place.
round([decimals, out])
Return a with each element rounded to the given number of decimals.
searchsorted(v[, side, sorter])
Find indices where elements of v should be inserted in a to maintain order.
setfield(val, dtype[, offset])
Put a value into a specified place in a field defined by a data-type.
setflags([write, align, uic])
Set array flags WRITEABLE, ALIGNED, (WRITEBACKIFCOPY and UPDATEIFCOPY), respectively.
sort([axis, kind, order])
Sort an array in-place.
squeeze([axis])
Remove axes of length one from a.
std([axis, dtype, out, ddof, keepdims, where])
Returns the standard deviation of the array elements along given axis.
sum([axis, dtype, out, keepdims, initial, where])
Return the sum of the array elements over the given axis.
swapaxes(axis1, axis2)
Return a view of the array with axis1 and axis2 interchanged.
take(indices[, axis, out, mode])
Return an array formed from the elements of a at the given indices.
tobytes([order])
Construct Python bytes containing the raw data bytes in the array.
tofile(fid[, sep, format])
Write array to a file as text or binary (default).
tolist()
Return the array as an a.ndim-levels deep nested list of Python scalars.
tostring([order])
A compatibility alias for tobytes, with exactly the same behavior.
trace([offset, axis1, axis2, dtype, out])
Return the sum along diagonals of the array.
transpose(*axes)
Returns a view of the array with axes transposed.
var([axis, dtype, out, ddof, keepdims, where])
Returns the variance of the array elements, along given axis.
view([dtype][, type])
New view of array with the same data.
dot


Multidimensional index iterator.
Return an iterator yielding pairs of array coordinates and values.
Input array.
See also


An N-dimensional iterator object to index arrays.
Given the shape of an array, an ndindex instance iterates over the N-dimensional index of the array. At each iteration a tuple of indices is returned, the last dimension is iterated over first.
The size of each dimension of the array can be passed as individual parameters or as the elements of a tuple.
See also
Dimensions as individual arguments
Same dimensions - but in a tuple (3, 2, 1)
ndincr()
Increment the multi-dimensional index by one.


Efficient multi-dimensional iterator object to iterate over arrays. To get started using this object, see the introductory guide to array iteration.
The array(s) to iterate over.
Flags to control the behavior of the iterator.
This is a list of flags for each operand. At minimum, one of readonly, readwrite, or writeonly must be specified.
The required data type(s) of the operands. If copying or buffering is enabled, the data will be converted to/from their original types.
Controls the iteration order. ‘C’ means C order, ‘F’ means Fortran order, ‘A’ means ‘F’ order if all the arrays are Fortran contiguous, ‘C’ order otherwise, and ‘K’ means as close to the order the array elements appear in memory as possible. This also affects the element memory order of allocate operands, as they are allocated to be compatible with iteration order. Default is ‘K’.
Controls what kind of data casting may occur when making a copy or buffering. Setting this to ‘unsafe’ is not recommended, as it can adversely affect accumulations.
If provided, is a list of ints or None for each operands. The list of axes for an operand is a mapping from the dimensions of the iterator to the dimensions of the operand. A value of -1 can be placed for entries, causing that dimension to be treated as newaxis.
The desired shape of the iterator. This allows allocate operands with a dimension mapped by op_axes not corresponding to a dimension of a different operand to get a value not equal to 1 for that dimension.
When buffering is enabled, controls the size of the temporary buffers. Set to 0 for the default value.
nditer supersedes flatiter. The iterator implementation behind nditer is also exposed by the NumPy C API.
The Python exposure supplies two iteration interfaces, one which follows the Python iterator protocol, and another which mirrors the C-style do-while pattern. The native Python approach is better in most cases, but if you need the coordinates or index of an iterator, use the C-style pattern.
Here is how we might write an iter_add function, using the Python iterator protocol:
Here is the same function, but following the C-style pattern:
Here is an example outer product function:
Here is an example function which operates like a “lambda” ufunc:
If operand flags “writeonly” or “readwrite” are used the operands may be views into the original data with the WRITEBACKIFCOPY flag. In this case nditer must be used as a context manager or the nditer.close method must be called before using the result. The temporary data will be written back to the original data when the __exit__ function is called but not before:
It is important to note that once the iterator is exited, dangling references (like x in the example) may or may not share data with the original data a. If writeback semantics were active, i.e. if x.base.flags.writebackifcopy is True, then exiting the iterator will sever the connection between x and a, writing to x will no longer write to a. If writeback semantics are not active, then x.data will still point at some part of a.data, and writing to one will affect the other.
Context management and the close method appeared in version 1.15.0.
The data types of the values provided in value. This may be different from the operand data types if buffering is enabled. Valid only before the iterator is closed.
Whether the iteration over the operands is finished or not.
If True, the iterator was created with the delay_bufalloc flag, and no reset() function was called on it yet.
If True, the iterator was created with either the c_index or the f_index flag, and the property index can be used to retrieve it.
If True, the iterator was created with the multi_index flag, and the property multi_index can be used to retrieve it.
When the c_index or f_index flag was used, this property provides access to the index. Raises a ValueError if accessed and has_index is False.
Whether iteration requires access to the Python API, for example if one of the operands is an object array.
An index which matches the order of iteration.
Size of the iterator.
Structured view(s) of operands in memory, matching the reordered and optimized iterator access pattern. Valid only before the iterator is closed.
When the multi_index flag was used, this property provides access to the index. Raises a ValueError if accessed accessed and has_multi_index is False.
The dimensions of the iterator.
The number of iterator operands.
operands[Slice]
Shape tuple, the shape of the iterator.
Value of operands at current iteration. Normally, this is a tuple of array scalars, but if the flag external_loop is used, it is a tuple of one dimensional arrays.
close()
Resolve all writeback semantics in writeable operands.
copy()
Get a copy of the iterator in its current state.
debug_print()
Print the current state of the nditer instance and debug info to stdout.
enable_external_loop()
When the "external_loop" was not used during construction, but is desired, this modifies the iterator to behave as if the flag was specified.
iternext()
Check whether iterations are left, and perform a single internal iteration without returning the result.
remove_axis(i, /)
Removes axis i from the iterator.
remove_multi_index()
When the "multi_index" flag was specified, this removes it, allowing the internal iteration structure to be optimized further.
reset()
Reset the iterator to its initial state.


Numerical negative, element-wise.
Input array.
A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.
This condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.
For other keyword-only arguments, see the ufunc docs.
Returned array or scalar: y = -x. This is a scalar if x is a scalar.
The unary - operator can be used as a shorthand for np.negative on ndarrays.


Create nditers for use in nested loops
Create a tuple of nditer objects which iterate in nested loops over different axes of the op argument. The first iterator is used in the outermost loop, the last in the innermost loop. Advancing one will change the subsequent iterators to point at its new element.
The array(s) to iterate over.
Each item is used as an “op_axes” argument to an nditer
See nditer parameters of the same name
An nditer for each item in axes, outermost first
See also
Basic usage. Note how y is the “flattened” version of [a[:, 0, :], a[:, 1, 0], a[:, 2, :]] since we specified the first iter’s axes as [1]


A convenient alias for None, useful for indexing arrays.
Outer product, same as outer(x, y):
x[newaxis, :] is equivalent to x[newaxis] and x[None]:


Return the next floating-point value after x1 towards x2, element-wise.
Values to find the next representable value of.
The direction where to look for the next representable value of x1. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).
A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.
This condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.
For other keyword-only arguments, see the ufunc docs.
The next representable values of x1 in the direction of x2. This is a scalar if both x1 and x2 are scalars.


IEEE 754 floating point representation of negative infinity.
A floating point representation of negative infinity.
isinf : Shows which elements are positive or negative infinity
isposinf : Shows which elements are positive infinity
isneginf : Shows which elements are negative infinity
isnan : Shows which elements are Not a Number
isfinite : Shows which elements are finite (not one of Not a Number, positive infinity and negative infinity)
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity. Also that positive infinity is not equivalent to negative infinity. But infinity is equivalent to positive infinity.


Return the indices of the elements that are non-zero.
Returns a tuple of arrays, one for each dimension of a, containing the indices of the non-zero elements in that dimension. The values in a are always tested and returned in row-major, C-style order.
To group the indices by element, rather than dimension, use argwhere, which returns a row for each non-zero element.
Note
When called on a zero-d array or scalar, nonzero(a) is treated as nonzero(atleast_1d(a)).
Deprecated since version 1.17.0: Use atleast_1d explicitly if this behavior is deliberate.
Input array.
Indices of elements that are non-zero.
See also
Return indices that are non-zero in the flattened version of the input array.
Equivalent ndarray method.
Counts the number of non-zero elements in the input array.
While the nonzero values can be obtained with a[nonzero(a)], it is recommended to use x[x.astype(bool)] or x[x != 0] instead, which will correctly handle 0-d arrays.
A common use for nonzero is to find the indices of an array, where a condition is True. Given an array a, the condition a > 3 is a boolean array and since False is interpreted as 0, np.nonzero(a > 3) yields the indices of the a where the condition is true.
Using this result to index a is equivalent to using the mask directly:
nonzero can also be called as a method of the array.


Return (x1 != x2) element-wise.
Input arrays. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).
A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.
This condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.
For other keyword-only arguments, see the ufunc docs.
Output array, element-wise comparison of x1 and x2. Typically of type bool, unless dtype=object is passed. This is a scalar if both x1 and x2 are scalars.
See also
The != operator can be used as a shorthand for np.not_equal on ndarrays.


Abstract base class of all numeric scalar types.


IEEE 754 floating point representation of negative zero.
A floating point representation of negative zero.
PZERO : Defines positive zero.
isinf : Shows which elements are positive or negative infinity.
isposinf : Shows which elements are positive infinity.
isneginf : Shows which elements are negative infinity.
isnan : Shows which elements are Not a Number.
Not a Number, positive infinity and negative infinity.
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). Negative zero is considered to be a finite number.


Return the scalar dtype or NumPy equivalent of Python type of an object.
The object of which the type is returned.
If given, this is returned for objects whose types can not be determined. If not given, None is returned for those objects.
The data type of rep.
See also


nd_grid instance which returns an open multi-dimensional “meshgrid”.
An instance of numpy.lib.index_tricks.nd_grid which returns an open (i.e. not fleshed out) mesh-grid when indexed, so that only one dimension of each returned array is greater than 1. The dimension and number of the output arrays are equal to the number of indexing dimensions. If the step length is not a complex number, then the stop is not inclusive.
However, if the step length is a complex number (e.g. 5j), then the integer part of its magnitude is interpreted as specifying the number of points to create between the start and stop values, where the stop value is inclusive.
ndarrays with only one dimension not equal to 1
See also
class of ogrid and mgrid objects
like ogrid but returns dense (or fleshed out) mesh grids
array concatenator


Return a new array of given shape and type, filled with ones.
Shape of the new array, e.g., (2, 3) or 2.
The desired data-type for the array, e.g., numpy.int8. Default is numpy.float64.
Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory.
Reference object to allow the creation of arrays which are not NumPy arrays. If an array-like passed in as like supports the __array_function__ protocol, the result will be defined by it. In this case, it ensures the creation of an array object compatible with that passed in via this argument.
New in version 1.20.0.
Array of ones with the given shape, dtype, and order.
See also
Return an array of ones with shape and type of input.
Return a new uninitialized array.
Return a new array setting values to zero.
Return a new array of given shape filled with value.


Return an array of ones with the same shape and type as a given array.
The shape and data-type of a define these same attributes of the returned array.
Overrides the data type of the result.
New in version 1.6.0.
Overrides the memory layout of the result. ‘C’ means C-order, ‘F’ means F-order, ‘A’ means ‘F’ if a is Fortran contiguous, ‘C’ otherwise. ‘K’ means match the layout of a as closely as possible.
New in version 1.6.0.
If True, then the newly created array will use the sub-class type of a, otherwise it will be a base-class array. Defaults to True.
Overrides the shape of the result. If order=’K’ and the number of dimensions is unchanged, will try to keep order, otherwise, order=’C’ is implied.
New in version 1.17.0.
Array of ones with the same shape and type as a.
See also
Return an empty array with shape and type of input.
Return an array of zeros with shape and type of input.
Return a new array with shape of input filled with value.
Return a new array setting values to one.


Compute the outer product of two vectors.
Given two vectors, a = [a0, a1, ..., aM] and b = [b0, b1, ..., bN], the outer product [1] is:
First input vector. Input is flattened if not already 1-dimensional.
Second input vector. Input is flattened if not already 1-dimensional.
A location where the result is stored
New in version 1.9.0.
out[i, j] = a[i] * b[j]
See also
einsum('i,j->ij', a.ravel(), b.ravel()) is the equivalent.
A generalization to dimensions other than 1D and other operations. np.multiply.outer(a.ravel(), b.ravel()) is the equivalent.
np.tensordot(a.ravel(), b.ravel(), axes=((), ())) is the equivalent.
: G. H. Golub and C. F. Van Loan, Matrix Computations, 3rd ed., Baltimore, MD, Johns Hopkins University Press, 1996, pg. 8.
Make a (very coarse) grid for computing a Mandelbrot set:
An example using a “vector” of letters:


Packs the elements of a binary-valued array into bits in a uint8 array.
The result is padded to full bytes by inserting zero bits at the end.
An array of integers or booleans whose elements should be packed to bits.
The dimension over which bit-packing is done. None implies packing the flattened array.
The order of the input bits. ‘big’ will mimic bin(val), [0, 0, 0, 0, 0, 0, 1, 1] => 3 = 0b00000011, ‘little’ will reverse the order so [1, 1, 0, 0, 0, 0, 0, 0] => 3. Defaults to ‘big’.
New in version 1.17.0.
Array of type uint8 whose elements represent bits corresponding to the logical (0 or nonzero) value of the input elements. The shape of packed has the same number of dimensions as the input (unless axis is None, in which case the output is 1-D).
See also
Unpacks elements of a uint8 array into a binary-valued output array.
Note that in binary 160 = 1010 0000, 64 = 0100 0000, 192 = 1100 0000, and 32 = 0010 0000.


Pad an array.
The array to pad.
Number of values padded to the edges of each axis. ((before_1, after_1), … (before_N, after_N)) unique pad widths for each axis. ((before, after),) yields same before and after pad for each axis. (pad,) or int is a shortcut for before = after = pad width for all axes.
One of the following string values or a user supplied function.
Pads with a constant value.
Pads with the edge values of array.
Pads with the linear ramp between end_value and the array edge value.
Pads with the maximum value of all or part of the vector along each axis.
Pads with the mean value of all or part of the vector along each axis.
Pads with the median value of all or part of the vector along each axis.
Pads with the minimum value of all or part of the vector along each axis.
Pads with the reflection of the vector mirrored on the first and last values of the vector along each axis.
Pads with the reflection of the vector mirrored along the edge of the array.
Pads with the wrap of the vector along the axis. The first values are used to pad the end and the end values are used to pad the beginning.
Pads with undefined values.
New in version 1.17.
Padding function, see Notes.
Used in ‘maximum’, ‘mean’, ‘median’, and ‘minimum’. Number of values at edge of each axis used to calculate the statistic value.
((before_1, after_1), … (before_N, after_N)) unique statistic lengths for each axis.
((before, after),) yields same before and after statistic lengths for each axis.
(stat_length,) or int is a shortcut for before = after = statistic length for all axes.
Default is None, to use the entire axis.
Used in ‘constant’. The values to set the padded values for each axis.
((before_1, after_1), ... (before_N, after_N)) unique pad constants for each axis.
((before, after),) yields same before and after constants for each axis.
(constant,) or constant is a shortcut for before = after = constant for all axes.
Default is 0.
Used in ‘linear_ramp’. The values used for the ending value of the linear_ramp and that will form the edge of the padded array.
((before_1, after_1), ... (before_N, after_N)) unique end values for each axis.
((before, after),) yields same before and after end values for each axis.
(constant,) or constant is a shortcut for before = after = constant for all axes.
Default is 0.
Used in ‘reflect’, and ‘symmetric’. The ‘even’ style is the default with an unaltered reflection around the edge value. For the ‘odd’ style, the extended part of the array is created by subtracting the reflected values from two times the edge value.
Padded array of rank equal to array with shape increased according to pad_width.
New in version 1.7.0.
For an array with rank greater than 1, some of the padding of later axes is calculated from padding of previous axes. This is easiest to think about with a rank 2 array where the corners of the padded array are calculated by using padded values from the first axis.
The padding function, if used, should modify a rank 1 array in-place. It has the following signature:
where
A rank 1 array already padded with zeros. Padded values are vector[:iaxis_pad_width[0]] and vector[-iaxis_pad_width[1]:].
A 2-tuple of ints, iaxis_pad_width[0] represents the number of values padded at the beginning of vector where iaxis_pad_width[1] represents the number of values padded at the end of vector.
The axis currently being calculated.
Any keyword arguments the function requires.


Return a partitioned copy of an array.
Creates a copy of the array with its elements rearranged in such a way that the value of the element in k-th position is in the position it would be in a sorted array. All elements smaller than the k-th element are moved before this element and all equal or greater are moved behind it. The ordering of the elements in the two partitions is undefined.
New in version 1.8.0.
Array to be sorted.
Element index to partition by. The k-th value of the element will be in its final sorted position and all smaller elements will be moved before it and all equal or greater elements behind it. The order of all elements in the partitions is undefined. If provided with a sequence of k-th it will partition all elements indexed by k-th of them into their sorted position at once.
Deprecated since version 1.22.0: Passing booleans as index is deprecated.
Axis along which to sort. If None, the array is flattened before sorting. The default is -1, which sorts along the last axis.
Selection algorithm. Default is ‘introselect’.
When a is an array with fields defined, this argument specifies which fields to compare first, second, etc. A single field can be specified as a string. Not all fields need be specified, but unspecified fields will still be used, in the order in which they come up in the dtype, to break ties.
Array of the same type and shape as a.
See also
Method to sort an array in-place.
Indirect partition.
Full sorting
The various selection algorithms are characterized by their average speed, worst case performance, work space size, and whether they are stable. A stable sort keeps items with the same key in the same relative order. The available algorithms have the following properties:
kind
speed
worst case
work space
stable
‘introselect’
1
O(n)
0
no
All the partition algorithms make temporary copies of the data when partitioning along any but the last axis. Consequently, partitioning along the last axis is faster and uses less space than partitioning along any other axis.
The sort order for complex numbers is lexicographic. If both the real and imaginary parts are non-nan then the order is determined by the real parts except when they are equal, in which case the order is determined by the imaginary parts.


Compute the q-th percentile of the data along the specified axis.
Returns the q-th percentile(s) of the array elements.
Input array or object that can be converted to an array.
Percentile or sequence of percentiles to compute, which must be between 0 and 100 inclusive.
Axis or axes along which the percentiles are computed. The default is to compute the percentile(s) along a flattened version of the array.
Changed in version 1.9.0: A tuple of axes is supported
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output, but the type (of the output) will be cast if necessary.
If True, then allow the input array a to be modified by intermediate calculations, to save memory. In this case, the contents of the input a after this function completes is undefined.
This parameter specifies the method to use for estimating the percentile. There are many different methods, some unique to NumPy. See the notes for explanation. The options sorted by their R type as summarized in the H&F paper [1] are:
The first three methods are discontiuous. NumPy further defines the following discontinuous variations of the default ‘linear’ (7.) option:
Changed in version 1.22.0: This argument was previously called “interpolation” and only offered the “linear” default and last four options.
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original array a.
New in version 1.9.0.
Deprecated name for the method keyword argument.
Deprecated since version 1.22.0.
If q is a single percentile and axis=None, then the result is a scalar. If multiple percentiles are given, first axis of the result corresponds to the percentiles. The other axes are the axes that remain after the reduction of a. If the input contains integers or floats smaller than float64, the output data-type is float64. Otherwise, the output data-type is the same as that of the input. If out is specified, that array is returned instead.
See also
equivalent to percentile(..., 50)
equivalent to percentile, except q in the range [0, 1].
Given a vector V of length N, the q-th percentile of V is the value q/100 of the way from the minimum to the maximum in a sorted copy of V. The values and distances of the two nearest neighbors as well as the method parameter will determine the percentile if the normalized ranking does not match the location of q exactly. This function is the same as the median if q=50, the same as the minimum if q=0 and the same as the maximum if q=100.
This optional method parameter specifies the method to use when the desired quantile lies between two data points i < j. If g is the fractional part of the index surrounded by i and alpha and beta are correction constants modifying i and j.
Below, ‘q’ is the quantile value, ‘n’ is the sample size and alpha and beta are constants. The following formula gives an interpolation “i + g” of where the quantile would be in the sorted sample. With ‘i’ being the floor and ‘g’ the fractional part of the result.
The different methods then work as follows
method 1 of H&F [1]. This method gives discontinuous results: * if g > 0 ; then take j * if g = 0 ; then take i
method 2 of H&F [1]. This method give discontinuous results: * if g > 0 ; then take j * if g = 0 ; then average between bounds
method 3 of H&F [1]. This method give discontinuous results: * if g > 0 ; then take j * if g = 0 and index is odd ; then take j * if g = 0 and index is even ; then take i
method 4 of H&F [1]. This method give continuous results using: * alpha = 0 * beta = 1
method 5 of H&F [1]. This method give continuous results using: * alpha = 1/2 * beta = 1/2
method 6 of H&F [1]. This method give continuous results using: * alpha = 0 * beta = 0
method 7 of H&F [1]. This method give continuous results using: * alpha = 1 * beta = 1
method 8 of H&F [1]. This method is probably the best method if the sample distribution function is unknown (see reference). This method give continuous results using: * alpha = 1/3 * beta = 1/3
method 9 of H&F [1]. This method is probably the best method if the sample distribution function is known to be normal. This method give continuous results using: * alpha = 3/8 * beta = 3/8
NumPy method kept for backwards compatibility. Takes i as the interpolation point.
NumPy method kept for backwards compatibility. Takes j as the interpolation point.
NumPy method kept for backwards compatibility. Takes i or j, whichever is nearest.
NumPy method kept for backwards compatibility. Uses (i + j) / 2.
R. J. Hyndman and Y. Fan, “Sample quantiles in statistical packages,” The American Statistician, 50(4), pp. 361-365, 1996
The different methods can be visualized graphically:


Evaluate a piecewise-defined function.
Given a set of conditions and corresponding functions, evaluate each function on the input data wherever its condition is true.
The input domain.
Each boolean array corresponds to a function in funclist. Wherever condlist[i] is True, funclist[i](x) is used as the output value.
Each boolean array in condlist selects a piece of x, and should therefore be of the same shape as x.
The length of condlist must correspond to that of funclist. If one extra function is given, i.e. if len(funclist) == len(condlist) + 1, then that extra function is the default value, used wherever all conditions are false.
Each function is evaluated over x wherever its corresponding condition is True. It should take a 1d array as input and give an 1d array or a scalar value as output. If, instead of a callable, a scalar is provided then a constant function (lambda x: scalar) is assumed.
Any further arguments given to piecewise are passed to the functions upon execution, i.e., if called piecewise(..., ..., 1, 'a'), then each function is called as f(x, 1, 'a').
Keyword arguments used in calling piecewise are passed to the functions upon execution, i.e., if called piecewise(..., ..., alpha=1), then each function is called as f(x, alpha=1).
The output is the same shape and type as x and is found by calling the functions in funclist on the appropriate portions of x, as defined by the boolean arrays in condlist. Portions not covered by any condition have a default value of 0.
See also
This is similar to choose or select, except that functions are evaluated on elements of x that satisfy the corresponding condition from condlist.
The result is:
Define the sigma function, which is -1 for x < 0 and +1 for x >= 0.
Define the absolute value, which is -x for x <0 and x for x >= 0.
Apply the same function to a scalar value.


IEEE 754 floating point representation of (positive) infinity.
Use inf because Inf, Infinity, PINF and infty are aliases for inf. For more details, see inf.
inf


Change elements of an array based on conditional and input values.
Similar to np.copyto(arr, vals, where=mask), the difference is that place uses the first N elements of vals, where N is the number of True values in mask, while copyto uses the elements where mask is True.
Note that extract does the exact opposite of place.
Array to put data into.
Boolean mask array. Must have the same size as a.
Values to put into a. Only the first N elements are used, where N is the number of True values in mask. If vals is smaller than N, it will be repeated, and if elements of a are to be masked, this sequence must be non-empty.
See also


Find the coefficients of a polynomial with the given sequence of roots.
Note
This forms part of the old polynomial API. Since version 1.4, the new polynomial API defined in numpy.polynomial is preferred. A summary of the differences can be found in the transition guide.
Returns the coefficients of the polynomial whose leading coefficient is one for the given sequence of zeros (multiple roots must be included in the sequence as many times as their multiplicity; see Examples). A square matrix (or array, which will be treated as a matrix) can also be given, in which case the coefficients of the characteristic polynomial of the matrix are returned.
A sequence of polynomial roots, or a square array or matrix object.
1D array of polynomial coefficients from highest to lowest degree:
c[0] * x**(N) + c[1] * x**(N-1) + ... + c[N-1] * x + c[N] where c[0] always equals 1.
If input is the wrong shape (the input must be a 1-D or square 2-D array).
See also
Compute polynomial values.
Return the roots of a polynomial.
Least squares polynomial fit.
A one-dimensional polynomial class.
Specifying the roots of a polynomial still leaves one degree of freedom, typically represented by an undetermined leading coefficient. [1] In the case of this function, that coefficient - the first one in the returned array - is always taken as one. (If for some reason you have one other point, the only automatic way presently to leverage that information is to use polyfit.)
The characteristic polynomial, \(p_a(t)\), of an n-by-n matrix A is given by
\(p_a(t) = \mathrm{det}(t\, \mathbf{I} - \mathbf{A})\),
where I is the n-by-n identity matrix. [2]
M. Sullivan and M. Sullivan, III, “Algebra and Trignometry, Enhanced With Graphing Utilities,” Prentice-Hall, pg. 318, 1996.
G. Strang, “Linear Algebra and Its Applications, 2nd Edition,” Academic Press, pg. 182, 1980.
Given a sequence of a polynomial’s zeros:
The line above represents z**3 + 0*z**2 + 0*z + 0.
The line above represents z**3 - z/4
Given a square array object:
Note how in all cases the leading coefficient is always 1.


A one-dimensional polynomial class.
Note
This forms part of the old polynomial API. Since version 1.4, the new polynomial API defined in numpy.polynomial is preferred. A summary of the differences can be found in the transition guide.
A convenience class, used to encapsulate “natural” operations on polynomials so that said operations may take on their customary form in code (see Examples).
The polynomial’s coefficients, in decreasing powers, or if the value of the second parameter is True, the polynomial’s roots (values where the polynomial evaluates to 0). For example, poly1d([1, 2, 3]) returns an object that represents \(x^2 + 2x + 3\), whereas poly1d([1, 2, 3], True) returns one that represents \((x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x -6\).
If True, c_or_r specifies the polynomial’s roots; the default is False.
Changes the variable used when printing p from x to variable (see Examples).
Construct the polynomial \(x^2 + 2x + 3\):
Evaluate the polynomial at \(x = 0.5\):
Find the roots:
These numbers in the previous line represent (0, 0) to machine precision
Show the coefficients:
Display the order (the leading zero-coefficients are removed):
Show the coefficient of the k-th power in the polynomial (which is equivalent to p.c[-(i+1)]):
Polynomials can be added, subtracted, multiplied, and divided (returns quotient and remainder):
asarray(p) gives the coefficient array, so polynomials can be used in all functions that accept arrays:
The variable used in the string representation of p can be modified, using the variable parameter:
Construct a polynomial from its roots:
This is the same polynomial as obtained by:
The polynomial coefficients
The polynomial coefficients
The polynomial coefficients
The polynomial coefficients
The order or degree of the polynomial
The order or degree of the polynomial
The roots of the polynomial, where self(x) == 0
The roots of the polynomial, where self(x) == 0
The name of the polynomial variable
__call__(val)
Call self as a function.
deriv([m])
Return a derivative of this polynomial.
integ([m, k])
Return an antiderivative (indefinite integral) of this polynomial.


Find the sum of two polynomials.
Note
This forms part of the old polynomial API. Since version 1.4, the new polynomial API defined in numpy.polynomial is preferred. A summary of the differences can be found in the transition guide.
Returns the polynomial resulting from the sum of two input polynomials. Each input must be either a poly1d object or a 1D sequence of polynomial coefficients, from highest to lowest degree.
Input polynomials.
The sum of the inputs. If either input is a poly1d object, then the output is also a poly1d object. Otherwise, it is a 1D array of polynomial coefficients from highest to lowest degree.
See also
A one-dimensional polynomial class.
Using poly1d objects:


Return the derivative of the specified order of a polynomial.
Note
This forms part of the old polynomial API. Since version 1.4, the new polynomial API defined in numpy.polynomial is preferred. A summary of the differences can be found in the transition guide.
Polynomial to differentiate. A sequence is interpreted as polynomial coefficients, see poly1d.
Order of differentiation (default: 1)
A new polynomial representing the derivative.
See also
Anti-derivative of a polynomial.
Class for one-dimensional polynomials.
The derivative of the polynomial \(x^3 + x^2 + x^1 + 1\) is:
which evaluates to:
We can verify this, approximating the derivative with (f(x + h) - f(x))/h:
The fourth-order derivative of a 3rd-order polynomial is zero:


Returns the quotient and remainder of polynomial division.
Note
This forms part of the old polynomial API. Since version 1.4, the new polynomial API defined in numpy.polynomial is preferred. A summary of the differences can be found in the transition guide.
The input arrays are the coefficients (including any coefficients equal to zero) of the “numerator” (dividend) and “denominator” (divisor) polynomials, respectively.
Dividend polynomial’s coefficients.
Divisor polynomial’s coefficients.
Coefficients, including those equal to zero, of the quotient.
Coefficients, including those equal to zero, of the remainder.
See also
Both u and v must be 0-d or 1-d (ndim = 0 or 1), but u.ndim need not equal v.ndim. In other words, all four possible combinations - u.ndim = v.ndim = 0, u.ndim = v.ndim = 1, u.ndim = 1, v.ndim = 0, and u.ndim = 0, v.ndim = 1 - work.


Least squares polynomial fit.
Note
This forms part of the old polynomial API. Since version 1.4, the new polynomial API defined in numpy.polynomial is preferred. A summary of the differences can be found in the transition guide.
Fit a polynomial p(x) = p[0] * x**deg + ... + p[deg] of degree deg to points (x, y). Returns a vector of coefficients p that minimises the squared error in the order deg, deg-1, … 0.
The Polynomial.fit class method is recommended for new code as it is more stable numerically. See the documentation of the method for more information.
x-coordinates of the M sample points (x[i], y[i]).
y-coordinates of the sample points. Several data sets of sample points sharing the same x-coordinates can be fitted at once by passing in a 2D-array that contains one dataset per column.
Degree of the fitting polynomial
Relative condition number of the fit. Singular values smaller than this relative to the largest singular value will be ignored. The default value is len(x)*eps, where eps is the relative precision of the float type, about 2e-16 in most cases.
Switch determining nature of return value. When it is False (the default) just the coefficients are returned, when True diagnostic information from the singular value decomposition is also returned.
Weights. If not None, the weight w[i] applies to the unsquared residual y[i] - y_hat[i] at x[i]. Ideally the weights are chosen so that the errors of the products w[i]*y[i] all have the same variance. When using inverse-variance weighting, use w[i] = 1/sigma(y[i]). The default value is None.
If given and not False, return not just the estimate but also its covariance matrix. By default, the covariance are scaled by chi2/dof, where dof = M - (deg + 1), i.e., the weights are presumed to be unreliable except in a relative sense and everything is scaled such that the reduced chi2 is unity. This scaling is omitted if cov='unscaled', as is relevant for the case that the weights are w = 1/sigma, with sigma known to be a reliable estimate of the uncertainty.
Polynomial coefficients, highest power first. If y was 2-D, the coefficients for k-th data set are in p[:,k].
These values are only returned if full == True
coefficient matrix
coefficient matrix
For more details, see numpy.linalg.lstsq.
Present only if full == False and cov == True. The covariance matrix of the polynomial coefficient estimates. The diagonal of this matrix are the variance estimates for each coefficient. If y is a 2-D array, then the covariance matrix for the k-th data set are in V[:,:,k]
The rank of the coefficient matrix in the least-squares fit is deficient. The warning is only raised if full == False.
The warnings can be turned off by
See also
Compute polynomial values.
Computes a least-squares fit.
Computes spline fits.
The solution minimizes the squared error
in the equations:
The coefficient matrix of the coefficients p is a Vandermonde matrix.
polyfit issues a RankWarning when the least-squares fit is badly conditioned. This implies that the best fit is not well-defined due to numerical error. The results may be improved by lowering the polynomial degree or by replacing x by x - x.mean(). The rcond parameter can also be set to a value smaller than its default, but the resulting fit may be spurious: including contributions from the small singular values can add numerical noise to the result.
Note that fitting polynomial coefficients is inherently badly conditioned when the degree of the polynomial is large or the interval of sample points is badly centered. The quality of the fit should always be checked in these cases. When polynomial fits are not satisfactory, splines may be a good alternative.
Wikipedia, “Curve fitting”, https://en.wikipedia.org/wiki/Curve_fitting
Wikipedia, “Polynomial interpolation”, https://en.wikipedia.org/wiki/Polynomial_interpolation
It is convenient to use poly1d objects for dealing with polynomials:
High-order polynomials may oscillate wildly:
Illustration:


Return an antiderivative (indefinite integral) of a polynomial.
Note
This forms part of the old polynomial API. Since version 1.4, the new polynomial API defined in numpy.polynomial is preferred. A summary of the differences can be found in the transition guide.
The returned order m antiderivative P of polynomial p satisfies \(\frac{d^m}{dx^m}P(x) = p(x)\) and is defined up to m - 1 integration constants k. The constants determine the low-order polynomial part
of P so that \(P^{(j)}(0) = k_{m-j-1}\).
Polynomial to integrate. A sequence is interpreted as polynomial coefficients, see poly1d.
Order of the antiderivative. (Default: 1)
Integration constants. They are given in the order of integration: those corresponding to highest-order terms come first.
If None (default), all constants are assumed to be zero. If m = 1, a single scalar can be given instead of a list.
See also
derivative of a polynomial
equivalent method
The defining property of the antiderivative:
The integration constants default to zero, but can be specified:
Note that 3 = 6 / 2!, and that the constants are given in the order of integrations. Constant of the highest-order polynomial term comes first:


Find the product of two polynomials.
Note
This forms part of the old polynomial API. Since version 1.4, the new polynomial API defined in numpy.polynomial is preferred. A summary of the differences can be found in the transition guide.
Finds the polynomial resulting from the multiplication of the two input polynomials. Each input must be either a poly1d object or a 1D sequence of polynomial coefficients, from highest to lowest degree.
Input polynomials.
The polynomial resulting from the multiplication of the inputs. If either inputs is a poly1d object, then the output is also a poly1d object. Otherwise, it is a 1D array of polynomial coefficients from highest to lowest degree.
See also
A one-dimensional polynomial class.
Array convolution. Same output as polymul, but has parameter for overlap mode.
Using poly1d objects:


A Chebyshev series class.
The Chebyshev class provides the standard Python numerical methods ‘+’, ‘-’, ‘*’, ‘//’, ‘%’, ‘divmod’, ‘**’, and ‘()’ as well as the methods listed below.
Chebyshev coefficients in order of increasing degree, i.e., (1, 2, 3) gives 1*T_0(x) + 2*T_1(x) + 3*T_2(x).
Domain to use. The interval [domain[0], domain[1]] is mapped to the interval [window[0], window[1]] by shifting and scaling. The default value is [-1, 1].
Window, see domain for its use. The default value is [-1, 1].
New in version 1.6.0.
__call__(arg)
Call self as a function.
basis(deg[, domain, window])
Series basis polynomial of degree deg.
cast(series[, domain, window])
Convert series to series of this class.
convert([domain, kind, window])
Convert series to a different kind and/or domain and/or window.
copy()
Return a copy.
cutdeg(deg)
Truncate series to the given degree.
degree()
The degree of the series.
deriv([m])
Differentiate.
fit(x, y, deg[, domain, rcond, full, w, window])
Least squares fit to data.
fromroots(roots[, domain, window])
Return series instance that has the specified roots.
has_samecoef(other)
Check if coefficients match.
has_samedomain(other)
Check if domains match.
has_sametype(other)
Check if types match.
has_samewindow(other)
Check if windows match.
identity([domain, window])
Identity function.
integ([m, k, lbnd])
Integrate.
interpolate(func, deg[, domain, args])
Interpolate a function at the Chebyshev points of the first kind.
linspace([n, domain])
Return x, y values at equally spaced points in domain.
mapparms()
Return the mapping parameters.
roots()
Return the roots of the series polynomial.
trim([tol])
Remove trailing coefficients
truncate(size)
Truncate series to length size.


An Hermite series class.
The Hermite class provides the standard Python numerical methods ‘+’, ‘-’, ‘*’, ‘//’, ‘%’, ‘divmod’, ‘**’, and ‘()’ as well as the attributes and methods listed in the ABCPolyBase documentation.
Hermite coefficients in order of increasing degree, i.e, (1, 2, 3) gives 1*H_0(x) + 2*H_1(X) + 3*H_2(x).
Domain to use. The interval [domain[0], domain[1]] is mapped to the interval [window[0], window[1]] by shifting and scaling. The default value is [-1, 1].
Window, see domain for its use. The default value is [-1, 1].
New in version 1.6.0.
__call__(arg)
Call self as a function.
basis(deg[, domain, window])
Series basis polynomial of degree deg.
cast(series[, domain, window])
Convert series to series of this class.
convert([domain, kind, window])
Convert series to a different kind and/or domain and/or window.
copy()
Return a copy.
cutdeg(deg)
Truncate series to the given degree.
degree()
The degree of the series.
deriv([m])
Differentiate.
fit(x, y, deg[, domain, rcond, full, w, window])
Least squares fit to data.
fromroots(roots[, domain, window])
Return series instance that has the specified roots.
has_samecoef(other)
Check if coefficients match.
has_samedomain(other)
Check if domains match.
has_sametype(other)
Check if types match.
has_samewindow(other)
Check if windows match.
identity([domain, window])
Identity function.
integ([m, k, lbnd])
Integrate.
linspace([n, domain])
Return x, y values at equally spaced points in domain.
mapparms()
Return the mapping parameters.
roots()
Return the roots of the series polynomial.
trim([tol])
Remove trailing coefficients
truncate(size)
Truncate series to length size.


An HermiteE series class.
The HermiteE class provides the standard Python numerical methods ‘+’, ‘-’, ‘*’, ‘//’, ‘%’, ‘divmod’, ‘**’, and ‘()’ as well as the attributes and methods listed in the ABCPolyBase documentation.
HermiteE coefficients in order of increasing degree, i.e, (1, 2, 3) gives 1*He_0(x) + 2*He_1(X) + 3*He_2(x).
Domain to use. The interval [domain[0], domain[1]] is mapped to the interval [window[0], window[1]] by shifting and scaling. The default value is [-1, 1].
Window, see domain for its use. The default value is [-1, 1].
New in version 1.6.0.
__call__(arg)
Call self as a function.
basis(deg[, domain, window])
Series basis polynomial of degree deg.
cast(series[, domain, window])
Convert series to series of this class.
convert([domain, kind, window])
Convert series to a different kind and/or domain and/or window.
copy()
Return a copy.
cutdeg(deg)
Truncate series to the given degree.
degree()
The degree of the series.
deriv([m])
Differentiate.
fit(x, y, deg[, domain, rcond, full, w, window])
Least squares fit to data.
fromroots(roots[, domain, window])
Return series instance that has the specified roots.
has_samecoef(other)
Check if coefficients match.
has_samedomain(other)
Check if domains match.
has_sametype(other)
Check if types match.
has_samewindow(other)
Check if windows match.
identity([domain, window])
Identity function.
integ([m, k, lbnd])
Integrate.
linspace([n, domain])
Return x, y values at equally spaced points in domain.
mapparms()
Return the mapping parameters.
roots()
Return the roots of the series polynomial.
trim([tol])
Remove trailing coefficients
truncate(size)
Truncate series to length size.


A Laguerre series class.
The Laguerre class provides the standard Python numerical methods ‘+’, ‘-’, ‘*’, ‘//’, ‘%’, ‘divmod’, ‘**’, and ‘()’ as well as the attributes and methods listed in the ABCPolyBase documentation.
Laguerre coefficients in order of increasing degree, i.e, (1, 2, 3) gives 1*L_0(x) + 2*L_1(X) + 3*L_2(x).
Domain to use. The interval [domain[0], domain[1]] is mapped to the interval [window[0], window[1]] by shifting and scaling. The default value is [0, 1].
Window, see domain for its use. The default value is [0, 1].
New in version 1.6.0.
__call__(arg)
Call self as a function.
basis(deg[, domain, window])
Series basis polynomial of degree deg.
cast(series[, domain, window])
Convert series to series of this class.
convert([domain, kind, window])
Convert series to a different kind and/or domain and/or window.
copy()
Return a copy.
cutdeg(deg)
Truncate series to the given degree.
degree()
The degree of the series.
deriv([m])
Differentiate.
fit(x, y, deg[, domain, rcond, full, w, window])
Least squares fit to data.
fromroots(roots[, domain, window])
Return series instance that has the specified roots.
has_samecoef(other)
Check if coefficients match.
has_samedomain(other)
Check if domains match.
has_sametype(other)
Check if types match.
has_samewindow(other)
Check if windows match.
identity([domain, window])
Identity function.
integ([m, k, lbnd])
Integrate.
linspace([n, domain])
Return x, y values at equally spaced points in domain.
mapparms()
Return the mapping parameters.
roots()
Return the roots of the series polynomial.
trim([tol])
Remove trailing coefficients
truncate(size)
Truncate series to length size.