Context manager for floating-point error handling.
Using an instance of errstate as a context manager allows statements in that context to execute with a known error handling behavior. Upon entering the context the error handling is set with seterr and seterrcall, and upon exiting it is reset to what it was before.
Changed in version 1.17.0: errstate is also usable as a function decorator, saving a level of indentation if an entire function is wrapped. See contextlib.ContextDecorator for more information.
Keyword arguments. The valid keywords are the possible floating-point exceptions. Each keyword should have a string value that defines the treatment for the particular error. Possible values are {‘ignore’, ‘warn’, ‘raise’, ‘call’, ‘print’, ‘log’}.
See also
For complete documentation of the types of floating-point exceptions and treatment options, see seterr.
Outside the context the error handling behavior has not changed:
__call__(func)
Call self as a function.


Calculate the exponential of all elements in the input array.
Input values.
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 exponential of x. This is a scalar if x is a scalar.
See also
Calculate exp(x) - 1 for all elements in the array.
Calculate 2**x for all elements in the array.
The irrational number e is also known as Euler’s number. It is approximately 2.718281, and is the base of the natural logarithm, ln (this means that, if \(x = \ln y = \log_e y\), then \(e^x = y\). For real input, exp(x) is always positive.
For complex arguments, x = a + ib, we can write \(e^x = e^a e^{ib}\). The first term, \(e^a\), is already known (it is the real argument, described above). The second term, \(e^{ib}\), is \(\cos b + i \sin b\), a function with magnitude 1 and a periodic phase.
Wikipedia, “Exponential function”, https://en.wikipedia.org/wiki/Exponential_function
M. Abramovitz and I. A. Stegun, “Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables,” Dover, 1964, p. 69, https://personal.math.ubc.ca/~cbm/aands/page_69.htm
Plot the magnitude and phase of exp(x) in the complex plane:


Calculate 2**p for all p in the input array.
Input values.
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.
Element-wise 2 to the power x. This is a scalar if x is a scalar.
See also
New in version 1.3.0.


Expand the shape of an array.
Insert a new axis that will appear at the axis position in the expanded array shape.
Input array.
Position in the expanded axes where the new axis (or axes) is placed.
Deprecated since version 1.13.0: Passing an axis where axis > a.ndim will be treated as axis == a.ndim, and passing axis < -a.ndim - 1 will be treated as axis == 0. This behavior is deprecated.
Changed in version 1.18.0: A tuple of axes is now supported. Out of range axes as described above are now forbidden and raise an AxisError.
View of a with the number of dimensions increased.
See also
The inverse operation, removing singleton dimensions
Insert, remove, and combine dimensions, and resize existing ones
The following is equivalent to x[np.newaxis, :] or x[np.newaxis]:
The following is equivalent to x[:, np.newaxis]:
axis may also be a tuple:
Note that some examples may use None instead of np.newaxis. These are the same objects:


Calculate exp(x) - 1 for all elements in the array.
Input values.
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.
Element-wise exponential minus one: out = exp(x) - 1. This is a scalar if x is a scalar.
See also
log(1 + x), the inverse of expm1.
This function provides greater precision than exp(x) - 1 for small values of x.
The true value of exp(1e-10) - 1 is 1.00000000005e-10 to about 32 significant digits. This example shows the superiority of expm1 in this case.


Return the elements of an array that satisfy some condition.
This is equivalent to np.compress(ravel(condition), ravel(arr)). If condition is boolean np.extract is equivalent to arr[condition].
Note that place does the exact opposite of extract.
An array whose nonzero or True entries indicate the elements of arr to extract.
Input array of the same size as condition.
Rank 1 array of values from arr where condition is True.
See also
If condition is boolean:


Return a 2-D array with ones on the diagonal and zeros elsewhere.
Number of rows in the output.
Number of columns in the output. If None, defaults to N.
Index of the diagonal: 0 (the default) refers to the main diagonal, a positive value refers to an upper diagonal, and a negative value to a lower diagonal.
Data-type of the returned array.
Whether the output should be stored in row-major (C-style) or column-major (Fortran-style) order in memory.
New in version 1.14.0.
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.
An array where all elements are equal to zero, except for the k-th diagonal, whose values are equal to one.
See also
(almost) equivalent function
diagonal 2-D array from a 1-D array specified by the user.


Return the directory that contains the fortranobject.c and .h files.
Note
This function is not needed when building an extension with numpy.distutils directly from .f and/or .pyf files in one go.
Python extension modules built with f2py-generated code need to use fortranobject.c as a source file, and include the fortranobject.h header. This function can be used to obtain the directory containing both of these files.
Absolute path to the directory containing fortranobject.c and fortranobject.h.
See also
function that returns the numpy include directory
New in version 1.22.0.
Unless the build system you are using has specific support for f2py, building a Python extension using a .pyf signature file is a two-step process. For a module mymod:
Step 2: build your Python extension module. This requires the following source files:


Equivalent to running:
where <args>=string.join(<list>,' '), but in Python. Unless -h is used, this function returns a dictionary containing information on generated modules and their dependencies on source files. For example, the command f2py -m scalar scalar.f can be executed from Python as follows
You cannot build extension modules with this function, that is, using -c is not allowed. Use compile command instead


Compute the absolute values element-wise.
This function returns the absolute values (positive magnitude) of the data in x. Complex values are not handled, use absolute to find the absolute values of complex data.
The array of numbers for which the absolute values are required. If x is a scalar, the result y will also be a scalar.
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 absolute values of x, the returned values are always floats. This is a scalar if x is a scalar.
See also
Absolute values including complex types.


Fill the main diagonal of the given array of any dimensionality.
For an array a with a.ndim >= 2, the diagonal is the list of locations with indices a[i, ..., i] all identical. This function modifies the input array in-place, it does not return a value.
Array whose diagonal is to be filled, it gets modified in-place.
Value(s) to write on the diagonal. If val is scalar, the value is written along the diagonal. If array-like, the flattened val is written along the diagonal, repeating if necessary to fill all diagonal entries.
For tall matrices in NumPy version up to 1.6.2, the diagonal “wrapped” after N columns. You can have this behavior with this option. This affects only tall matrices.
See also
New in version 1.4.0.
This functionality can be obtained via diag_indices, but internally this version uses a much faster implementation that never constructs the indices and uses simple slicing.
The same function can operate on a 4-D array:
We only show a few blocks for clarity:
The wrap option affects only tall matrices:
The anti-diagonal can be filled by reversing the order of elements using either numpy.flipud or numpy.fliplr.
Note that the order in which the diagonal is filled varies depending on the flip function.


Determine common type following standard coercion rules.
A list of dtypes or dtype convertible objects representing arrays.
A list of dtypes or dtype convertible objects representing scalars.
The common data type, which is the maximum of array_types ignoring scalar_types, unless the maximum of scalar_types is of a different kind (dtype.kind). If the kind is not understood, then None is returned.
See also
The standard casting rules ensure that a scalar cannot up-cast an array unless the scalar is of a fundamentally different kind of data (i.e. under a different hierarchy in the data type hierarchy) then the array:
Complex is of a different type, so it up-casts the float in the array_types argument:
Type specifier strings are convertible to dtypes and can therefore be used instead of dtypes:


Machine limits for floating point types.
Kind of floating point data-type about which to get information.
See also
The implementation of the tests that produce this information.
The equivalent for integer data types.
The distance between a value and the nearest adjacent number
The next floating point value after x1 towards x2
For developers of NumPy: do not instantiate this at the module level. The initial calculation of these parameters is expensive and negatively impacts import times. These objects are cached, so calling finfo() repeatedly inside your functions is not a problem.
Note that smallest_normal is not actually the smallest positive representable value in a NumPy floating point type. As in the IEEE-754 standard [1], NumPy floating point types make use of subnormal numbers to fill the gap between 0 and smallest_normal. However, subnormal numbers may have significantly reduced precision [2].
IEEE Standard for Floating-Point Arithmetic, IEEE Std 754-2008, pp.1-70, 2008, http://www.doi.org/10.1109/IEEESTD.2008.4610935
Wikipedia, “Denormal Numbers”, https://en.wikipedia.org/wiki/Denormal_number
The number of bits occupied by the type.
The difference between 1.0 and the next smallest representable float larger than 1.0. For example, for 64-bit binary floats in the IEEE-754 standard, eps = 2**-52, approximately 2.22e-16.
The difference between 1.0 and the next smallest representable float less than 1.0. For example, for 64-bit binary floats in the IEEE-754 standard, epsneg = 2**-53, approximately 1.11e-16.
The number of bits in the exponent portion of the floating point representation.
The object which calculated these parameters and holds more detailed information.
The exponent that yields eps.
The largest representable number.
The smallest positive power of the base (2) that causes overflow.
The smallest representable number, typically -max.
The most negative power of the base (2) consistent with there being no leading 0’s in the mantissa.
The exponent that yields epsneg.
The number of bits in the exponent including its sign and bias.
The number of bits in the mantissa.
The approximate number of decimal digits to which this kind of float is precise.
The approximate decimal resolution of this type, i.e., 10**-precision.
Return the value for tiny, alias of smallest_normal.
Return the value for the smallest normal.
The smallest positive floating point number with 0 as leading bit in the mantissa following IEEE-754.


Round to nearest integer towards zero.
Round an array of floats element-wise to nearest integer towards zero. The rounded values are returned as floats.
An array of floats to be rounded
A location into which the result is stored. If provided, it must have a shape that the input broadcasts to. If not provided or None, a freshly-allocated array is returned.
A float array with the same dimensions as the input. If second argument is not supplied then a float array is returned with the rounded values.
If a second argument is supplied the result is stored there. The return value out is then a reference to that array.
See also
Round to given number of decimals


Flat iterator object to iterate over arrays.
A flatiter iterator is returned by x.flat for any array x. It allows iterating over the array as if it were a 1-D array, either in a for-loop or by calling its next method.
Iteration is done in row-major, C-style order (the last index varying the fastest). The iterator can also be indexed using basic slicing or advanced indexing.
See also
Return a flat iterator over an array.
Returns a flattened copy of an array.
A flatiter iterator can not be constructed directly from Python code by calling the flatiter constructor.
A reference to the array that is iterated over.
An N-dimensional tuple of current coordinates.
Current flat index into the array.
copy()
Get a copy of the iterator as a 1-D array.


Return indices that are non-zero in the flattened version of a.
This is equivalent to np.nonzero(np.ravel(a))[0].
Input data.
Output array, containing the indices of the elements of a.ravel() that are non-zero.
See also
Return the indices of the non-zero elements of the input array.
Return a 1-D array containing the elements of the input array.
Use the indices of the non-zero elements as an index array to extract these elements:


Abstract base class of all scalar types without predefined length. The actual size of these types depends on the specific np.dtype instantiation.


Reverse the order of elements in an array along the given axis.
The shape of the array is preserved, but the elements are reordered.
New in version 1.12.0.
Input array.
Axis or axes along which to flip over. The default, axis=None, will flip over all of the axes of the input array. If axis is negative it counts from the last to the first axis.
If axis is a tuple of ints, flipping is performed on all of the axes specified in the tuple.
Changed in version 1.15.0: None and tuples of axes are supported
A view of m with the entries of axis reversed. Since a view is returned, this operation is done in constant time.
See also
Flip an array vertically (axis=0).
Flip an array horizontally (axis=1).
flip(m, 0) is equivalent to flipud(m).
flip(m, 1) is equivalent to fliplr(m).
flip(m, n) corresponds to m[...,::-1,...] with ::-1 at position n.
flip(m) corresponds to m[::-1,::-1,...,::-1] with ::-1 at all positions.
flip(m, (0, 1)) corresponds to m[::-1,::-1,...] with ::-1 at position 0 and position 1.


Reverse the order of elements along axis 1 (left/right).
For a 2-D array, this flips the entries in each row in the left/right direction. Columns are preserved, but appear in a different order than before.
Input array, must be at least 2-D.
A view of m with the columns reversed. Since a view is returned, this operation is \(\mathcal O(1)\).
See also
Flip array in the up/down direction.
Flip array in one or more dimensions.
Rotate array counterclockwise.
Equivalent to m[:,::-1] or np.flip(m, axis=1). Requires the array to be at least 2-D.


Reverse the order of elements along axis 0 (up/down).
For a 2-D array, this flips the entries in each column in the up/down direction. Rows are preserved, but appear in a different order than before.
Input array.
A view of m with the rows reversed. Since a view is returned, this operation is \(\mathcal O(1)\).
See also
Flip array in the left/right direction.
Flip array in one or more dimensions.
Rotate array counterclockwise.
Equivalent to m[::-1, ...] or np.flip(m, axis=0). Requires the array to be at least 1-D.


Alias for numpy.longdouble, named after its size in bits. The existence of these aliases depends on the platform.


First array elements raised to powers from second array, element-wise.
Raise each base in x1 to the positionally-corresponding power in x2. x1 and x2 must be broadcastable to the same shape. This differs from the power function in that integers, float16, and float32 are promoted to floats with a minimum precision of float64 so that the result is always inexact. The intent is that the function will return a usable result for negative powers and seldom overflow for positive powers.
Negative values raised to a non-integral value will return nan. To get complex results, cast the input to complex, or specify the dtype to be complex (see the example below).
New in version 1.12.0.
The bases.
The exponents. 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 bases in x1 raised to the exponents in x2. This is a scalar if both x1 and x2 are scalars.
See also
power function that preserves type
Cube each element in a list.
Raise the bases to different exponents.
The effect of broadcasting.
Negative values raised to a non-integral value will result in nan (and a warning will be generated).
To get complex results, give the argument dtype=complex.


Return the floor of the input, element-wise.
The floor of the scalar x is the largest integer i, such that i <= x. It is often denoted as \(\lfloor x \rfloor\).
Input data.
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 floor of each element in x. This is a scalar if x is a scalar.
See also
Some spreadsheet programs calculate the “floor-towards-zero”, where floor(-2.5) == -2. NumPy instead uses the definition of floor where floor(-2.5) == -3. The “floor-towards-zero” function is called fix in NumPy.


Return the largest integer smaller or equal to the division of the inputs. It is equivalent to the Python // operator and pairs with the Python % (remainder), function so that a = a % b + b * (a // b) up to roundoff.
Numerator.
Denominator. 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.
y = floor(x1/x2) This is a scalar if both x1 and x2 are scalars.
See also
Remainder complementary to floor_divide.
Simultaneous floor division and remainder.
Standard division.
Round a number to the nearest integer toward minus infinity.
Round a number to the nearest integer toward infinity.
The // operator can be used as a shorthand for np.floor_divide on ndarrays.


Element-wise maximum of array elements.
Compare two arrays and returns a new array containing the element-wise maxima. If one of the elements being compared is a NaN, then the non-nan 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 ignored when possible.
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 maximum of x1 and x2, element-wise. This is a scalar if both x1 and x2 are scalars.
See also
Element-wise minimum of two arrays, ignores NaNs.
Element-wise maximum of two arrays, propagates NaNs.
The maximum value of an array along a given axis, propagates NaNs.
The maximum value of an array along a given axis, ignores NaNs.
New in version 1.3.0.
The fmax is equivalent to np.where(x1 >= x2, x1, x2) when neither x1 nor x2 are NaNs, but it is faster and does proper broadcasting.


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 the non-nan 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 ignored when possible.
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, ignores NaNs.
Element-wise minimum of two arrays, propagates 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.
New in version 1.3.0.
The fmin is equivalent to np.where(x1 <= x2, x1, x2) when neither x1 nor x2 are NaNs, but it is faster and does proper broadcasting.


Returns the element-wise remainder of division.
This is the NumPy implementation of the C library function fmod, the remainder has the same sign as the dividend x1. It is equivalent to the Matlab(TM) rem function and should not be confused with the Python modulus operator x1 % x2.
Dividend.
Divisor. 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 remainder of the division of x1 by x2. This is a scalar if both x1 and x2 are scalars.
See also
Equivalent to the Python % operator.
The result of the modulo operation for negative dividend and divisors is bound by conventions. For fmod, the sign of result is the sign of the dividend, while for remainder the sign of the result is the sign of the divisor. The fmod function is equivalent to the Matlab(TM) rem function.


Format a floating-point scalar as a decimal string in positional notation.
Provides control over rounding, trimming and padding. Uses and assumes IEEE unbiased rounding. Uses the “Dragon4” algorithm.
Value to format.
Maximum number of digits to print. May be None if unique is True, but must be an integer if unique is False.
If True, use a digit-generation strategy which gives the shortest representation which uniquely identifies the floating-point number from other values of the same type, by judicious rounding. If precision is given fewer digits than necessary can be printed, or if min_digits is given more can be printed, in which cases the last digit is rounded with unbiased rounding. If False, digits are generated as if printing an infinite-precision value and stopping after precision digits, rounding the remaining value with unbiased rounding
If True, the cutoffs of precision and min_digits refer to the total number of digits after the decimal point, including leading zeros. If False, precision and min_digits refer to the total number of significant digits, before or after the decimal point, ignoring leading zeros.
Controls post-processing trimming of trailing digits, as follows:
Whether to show the sign for positive values.
Pad the left side of the string with whitespace until at least that many characters are to the left of the decimal point.
Pad the right side of the string with whitespace until at least that many characters are to the right of the decimal point.
Minimum number of digits to print. Only has an effect if unique=True in which case additional digits past those necessary to uniquely identify the value may be printed, rounding the last additional digit.
– versionadded:: 1.21.0
The string representation of the floating point value
See also


Format a floating-point scalar as a decimal string in scientific notation.
Provides control over rounding, trimming and padding. Uses and assumes IEEE unbiased rounding. Uses the “Dragon4” algorithm.
Value to format.
Maximum number of digits to print. May be None if unique is True, but must be an integer if unique is False.
If True, use a digit-generation strategy which gives the shortest representation which uniquely identifies the floating-point number from other values of the same type, by judicious rounding. If precision is given fewer digits than necessary can be printed. If min_digits is given more can be printed, in which cases the last digit is rounded with unbiased rounding. If False, digits are generated as if printing an infinite-precision value and stopping after precision digits, rounding the remaining value with unbiased rounding
Controls post-processing trimming of trailing digits, as follows:
Whether to show the sign for positive values.
Pad the left side of the string with whitespace until at least that many characters are to the left of the decimal point.
Pad the exponent with zeros until it contains at least this many digits. If omitted, the exponent will be at least 2 digits.
Minimum number of digits to print. This only has an effect for unique=True. In that case more digits than necessary to uniquely identify the value may be printed and rounded unbiased.
– versionadded:: 1.21.0
The string representation of the floating point value
See also


Class to convert formats, names, titles description to a dtype.
After constructing the format_parser object, the dtype attribute is the converted data-type: dtype = format_parser(formats, names, titles).dtype
The format description, either specified as a string with comma-separated format descriptions in the form 'f8, i4, a5', or a list of format description strings in the form ['f8', 'i4', 'a5'].
The field names, either specified as a comma-separated string in the form 'col1, col2, col3', or as a list or tuple of strings in the form ['col1', 'col2', 'col3']. An empty list can be used, in that case default field names (‘f0’, ‘f1’, …) are used.
Sequence of title strings. An empty list can be used to leave titles out.
If True, align the fields by padding as the C-compiler would. Default is False.
If specified, all the fields will be changed to the provided byte-order. Otherwise, the default byte-order is used. For all available string specifiers, see dtype.newbyteorder.
See also
names and/or titles can be empty lists. If titles is an empty list, titles will simply not appear. If names is empty, default field names will be used.
The converted data-type.


Decompose the elements of x into mantissa and twos exponent.
Returns (mantissa, exponent), where x = mantissa * 2**exponent`. The mantissa lies in the open interval(-1, 1), while the twos exponent is a signed integer.
Array of numbers to be decomposed.
Output array for the mantissa. Must have the same shape as x.
Output array for the exponent. Must have the same shape as x.
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.
Floating values between -1 and 1. This is a scalar if x is a scalar.
Integer exponents of 2. This is a scalar if x is a scalar.
See also
Compute y = x1 * 2**x2, the inverse of frexp.
Complex dtypes are not supported, they will raise a TypeError.


Interpret a buffer as a 1-dimensional array.
An object that exposes the buffer interface.
Data-type of the returned array; default: float.
Number of items to read. -1 means all data in the buffer.
Start reading the buffer from this offset (in bytes); default: 0.
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.
If the buffer has data that is not in machine byte-order, this should be specified as part of the data-type, e.g.:
The data of the resulting array will not be byteswapped, but will be interpreted correctly.


Construct an array from data in a text or binary file.
A highly efficient way of reading binary data with a known data-type, as well as parsing simply formatted text files. Data written using the tofile method can be read using this function.
Open file object or filename.
Changed in version 1.17.0: pathlib.Path objects are now accepted.
Data type of the returned array. For binary files, it is used to determine the size and byte-order of the items in the file. Most builtin numeric types are supported and extension types may be supported.
New in version 1.18.0: Complex dtypes.
Number of items to read. -1 means all items (i.e., the complete file).
Separator between items if file is a text file. Empty (“”) separator means the file should be treated as binary. Spaces (” “) in the separator match zero or more whitespace characters. A separator consisting only of spaces must match at least one whitespace.
The offset (in bytes) from the file’s current position. Defaults to 0. Only permitted for binary files.
New in version 1.17.0.
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.
See also
More flexible way of loading data from a text file.
Do not rely on the combination of tofile and fromfile for data storage, as the binary files generated are not platform independent. In particular, no byte-order or data-type information is saved. Data can be stored in the platform independent .npy format using save and load instead.
Construct an ndarray:
Save the raw data to disk:
Read the raw data from disk:
The recommended way to store and load data:


Construct an array by executing a function over each coordinate.
The resulting array therefore has a value fn(x, y, z) at coordinate (x, y, z).
The function is called with N parameters, where N is the rank of shape. Each parameter represents the coordinates of the array varying along a specific axis. For example, if shape were (2, 2), then the parameters would be array([[0, 0], [1, 1]]) and array([[0, 1], [0, 1]])
Shape of the output array, which also determines the shape of the coordinate arrays passed to function.
Data-type of the coordinate arrays passed to function. By default, dtype is float.
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.
The result of the call to function is passed back directly. Therefore the shape of fromfunction is completely determined by function. If function returns a scalar value, the shape of fromfunction would not match the shape parameter.
See also
Keywords other than dtype are passed to function.


Create a new 1-dimensional array from an iterable object.
An iterable object providing data for the array.
The data-type of the returned array.
The number of items to read from iterable. The default is -1, which means all data is read.
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.
The output array.
Specify count to improve performance. It allows fromiter to pre-allocate the output array, instead of resizing it on demand.


Takes an arbitrary Python function and returns a NumPy ufunc.
Can be used, for example, to add broadcasting to a built-in Python function (see Examples section).
An arbitrary Python function.
The number of input arguments.
The number of objects returned by func.
The value to use for the identity attribute of the resulting object. If specified, this is equivalent to setting the underlying C identity field to PyUFunc_IdentityValue. If omitted, the identity is set to PyUFunc_None. Note that this is _not_ equivalent to setting the identity to None, which implies the operation is reorderable.
Returns a NumPy universal function (ufunc) object.
See also
Evaluates pyfunc over input arrays using broadcasting rules of numpy.
The returned ufunc always returns PyObject arrays.
Use frompyfunc to add broadcasting to the Python function oct:


Construct an array from a text file, using regular expression parsing.
The returned array is always a structured array, and is constructed from all matches of the regular expression in the file. Groups in the regular expression are converted to fields of the structured array.
Filename or file object to read.
Changed in version 1.22.0: Now accepts os.PathLike implementations.
Regular expression used to parse the file. Groups in the regular expression correspond to fields in the dtype.
Dtype for the structured array; must be a structured datatype.
Encoding used to decode the inputfile. Does not apply to input streams.
New in version 1.14.0.
The output array, containing the part of the content of file that was matched by regexp. output is always a structured array.
When dtype is not a valid dtype for a structured array.
See also
Dtypes for structured arrays can be specified in several forms, but all forms specify at least the data type and field name. For details see basics.rec.


A new 1-D array initialized from text data in a string.
A string containing the data.
The data type of the array; default: float. For binary input data, the data must be in exactly this format. Most builtin numeric types are supported and extension types may be supported.
New in version 1.18.0: Complex dtypes.
Read this number of dtype elements from the data. If this is negative (the default), the count will be determined from the length of the data.
The string separating numbers in the data; extra whitespace between elements is also ignored.
Deprecated since version 1.14: Passing sep='', the default, is deprecated since it will trigger the deprecated binary mode of this function. This mode interprets string as binary bytes, rather than ASCII text with decimal numbers, an operation which is better spelt frombuffer(string, dtype, count). If string contains unicode text, the binary mode of fromstring will first encode it into bytes using either utf-8 (python 3) or the default encoding (python 2), neither of which produce sane results.
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.
The constructed array.
If the string is not the correct size to satisfy the requested dtype and count.
See also


Return a new array of given shape and type, filled with fill_value.
Shape of the new array, e.g., (2, 3) or 2.
Fill value.
np.array(fill_value).dtype.
Whether to store multidimensional data in C- or Fortran-contiguous (row- or column-wise) 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 fill_value with the given shape, dtype, and order.
See also
Return a new array with shape of input filled with value.
Return a new uninitialized array.
Return a new array setting values to one.
Return a new array setting values to zero.


Return a full array 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.
Fill value.
Overrides the data type of the result.
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.
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 fill_value with the same shape and type as a.
See also
Return an empty array with shape and type of input.
Return an array of ones with shape and type of input.
Return an array of zeros with shape and type of input.
Return a new array of given shape filled with value.


Returns the greatest common divisor of |x1| and |x2|
Arrays of values. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).
The greatest common divisor of the absolute value of the inputs This is a scalar if both x1 and x2 are scalars.
See also
The lowest common multiple


Load data from a text file, with missing values handled as specified.
Each line past the first skip_header lines is split at the delimiter character, and characters following the comments character are discarded.
File, filename, list, or generator to read. If the filename extension is .gz or .bz2, the file is first decompressed. Note that generators must return bytes or strings. The strings in a list or produced by a generator are treated as lines.
Data type of the resulting array. If None, the dtypes will be determined by the contents of each column, individually.
The character used to indicate the start of a comment. All the characters occurring on a line after a comment are discarded.
The string used to separate values. By default, any consecutive whitespaces act as delimiter. An integer or sequence of integers can also be provided as width(s) of each field.
skiprows was removed in numpy 1.10. Please use skip_header instead.
The number of lines to skip at the beginning of the file.
The number of lines to skip at the end of the file.
The set of functions that convert the data of a column to a value. The converters can also be used to provide a default value for missing data: converters = {3: lambda s: float(s or 0)}.
missing was removed in numpy 1.10. Please use missing_values instead.
The set of strings corresponding to missing data.
The set of values to be used as default when the data are missing.
Which columns to read, with 0 being the first. For example, usecols = (1, 4, 5) will extract the 2nd, 5th and 6th columns.
If names is True, the field names are read from the first line after the first skip_header lines. This line can optionally be preceded by a comment delimiter. If names is a sequence or a single-string of comma-separated names, the names will be used to define the field names in a structured dtype. If names is None, the names of the dtype fields will be used, if any.
A list of names to exclude. This list is appended to the default list [‘return’,’file’,’print’]. Excluded names are appended with an underscore: for example, file would become file_.
A string combining invalid characters that must be deleted from the names.
A format used to define default field names, such as “f%i” or “f_%02i”.
Whether to automatically strip white spaces from the variables.
Character(s) used in replacement of white spaces in the variable names. By default, use a ‘_’.
If True, field names are case sensitive. If False or ‘upper’, field names are converted to upper case. If ‘lower’, field names are converted to lower case.
If True, the returned array is transposed, so that arguments may be unpacked using x, y, z = genfromtxt(...). When used with a structured data-type, arrays are returned for each field. Default is False.
If True, return a masked array. If False, return a regular array.
If True, do not raise errors for invalid values.
If True, an exception is raised if an inconsistency is detected in the number of columns. If False, a warning is emitted and the offending lines are skipped.
The maximum number of rows to read. Must not be used with skip_footer at the same time. If given, the value must be at least 1. Default is to read the entire file.
New in version 1.10.0.
Encoding used to decode the inputfile. Does not apply when fname is a file object. The special value ‘bytes’ enables backward compatibility workarounds that ensure that you receive byte arrays when possible and passes latin1 encoded strings to converters. Override this value to receive unicode arrays and pass strings as input to converters. If set to None the system default is used. The default value is ‘bytes’.
New in version 1.14.0.
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.
Data read from the text file. If usemask is True, this is a masked array.
See also
equivalent function when no data is missing.
NumPy User Guide, section I/O with NumPy.
Comma delimited file with mixed dtype
Using dtype = None
Specifying dtype and names
An example with fixed-width columns
An example to show comments


Return numbers spaced evenly on a log scale (a geometric progression).
This is similar to logspace, but with endpoints specified directly. Each output sample is a constant multiple of the previous.
Changed in version 1.16.0: Non-scalar start and stop are now supported.
The starting value of the sequence.
The final value of the sequence, unless endpoint is False. In that case, num + 1 values are spaced over the interval in log-space, of which all but the last (a sequence of length num) are returned.
Number of samples to generate. Default is 50.
If true, stop is the last sample. Otherwise, it is not included. Default is True.
The type of the output array. If dtype is not given, the data type is inferred from start and stop. The inferred dtype will never be an integer; float is chosen even if the arguments would produce an array of integers.
The axis in the result to store the samples. Relevant only if start or stop are array-like. By default (0), the samples will be along a new axis inserted at the beginning. Use -1 to get an axis at the end.
New in version 1.16.0.
num samples, equally spaced on a log scale.
See also
Similar to geomspace, but with endpoints specified using log and base.
Similar to geomspace, but with arithmetic instead of geometric progression.
Similar to linspace, with the step size specified instead of the number of samples.
If the inputs or dtype are complex, the output will follow a logarithmic spiral in the complex plane. (There are an infinite number of spirals passing through two points; the output will follow the shortest such path.)
Note that the above may not produce exact integers:
Negative, decreasing, and complex inputs are allowed:
Graphical illustration of endpoint parameter:


Return the directory that contains the NumPy *.h header files.
Extension modules that need to compile against NumPy should use this function to locate the appropriate include directory.
When using distutils, for example in setup.py.


Return the current print options.
Dictionary of current print options with keys
For a full description of these options, see set_printoptions.
See also


Return the size of the buffer used in ufuncs.
Size of ufunc buffer in bytes.


Get the current way of handling floating-point errors.
A dictionary with keys “divide”, “over”, “under”, and “invalid”, whose values are from the strings “ignore”, “print”, “log”, “warn”, “raise”, and “call”. The keys represent possible floating-point exceptions, and the values define how these exceptions are handled.
See also
For complete documentation of the types of floating-point exceptions and treatment options, see seterr.


Return the current callback function used on floating-point errors.
When the error handling for a floating-point error (one of “divide”, “over”, “under”, or “invalid”) is set to ‘call’ or ‘log’, the function that is called or the log instance that is written to is returned by geterrcall. This function or log instance has been set with seterrcall.
The current error handler. If no handler was set through seterrcall, None is returned.
See also
For complete documentation of the types of floating-point exceptions and treatment options, see seterr.


Return the current object that defines floating-point error handling.
The error object contains all information that defines the error handling behavior in NumPy. geterrobj is used internally by the other functions that get and set error handling behavior (geterr, seterr, geterrcall, seterrcall).
The error object, a list containing three elements: [internal numpy buffer size, error mask, error callback function].
The error mask is a single integer that holds the treatment information on all four floating point errors. The information for each error type is contained in three bits of the integer. If we print it in base 8, we can see what treatment is set for “invalid”, “under”, “over”, and “divide” (in that order). The printed string can be interpreted with
See also
For complete documentation of the types of floating-point exceptions and treatment options, see seterr.


Return the gradient of an N-dimensional array.
The gradient is computed using second order accurate central differences in the interior points and either first or second order accurate one-sides (forward or backwards) differences at the boundaries. The returned gradient hence has the same shape as the input array.
An N-dimensional array containing samples of a scalar function.
Spacing between f values. Default unitary spacing for all dimensions. Spacing can be specified using:
If axis is given, the number of varargs must equal the number of axes. Default: 1.
Gradient is calculated using N-th order accurate differences at the boundaries. Default: 1.
New in version 1.9.1.
Gradient is calculated only along the given axis or axes The default (axis = None) is to calculate the gradient for all the axes of the input array. axis may be negative, in which case it counts from the last to the first axis.
New in version 1.11.0.
A list of ndarrays (or a single ndarray if there is only one dimension) corresponding to the derivatives of f with respect to each dimension. Each derivative has the same shape as f.
Assuming that \(f\in C^{3}\) (i.e., \(f\) has at least 3 continuous derivatives) and let \(h_{*}\) be a non-homogeneous stepsize, we minimize the “consistency error” \(\eta_{i}\) between the true gradient and its estimate from a linear combination of the neighboring grid-points:
By substituting \(f(x_{i} + h_{d})\) and \(f(x_{i} - h_{s})\) with their Taylor series expansion, this translates into solving the following the linear system:
The resulting approximation of \(f_{i}^{(1)}\) is the following:
It is worth noting that if \(h_{s}=h_{d}\) (i.e., data are evenly spaced) we find the standard second order approximation:
With a similar procedure the forward/backward approximations used for boundaries can be derived.
Quarteroni A., Sacco R., Saleri F. (2007) Numerical Mathematics (Texts in Applied Mathematics). New York: Springer.
Durran D. R. (1999) Numerical Methods for Wave Equations in Geophysical Fluid Dynamics. New York: Springer.
Fornberg B. (1988) Generation of Finite Difference Formulas on Arbitrarily Spaced Grids, Mathematics of Computation 51, no. 184 : 699-706. PDF.
Spacing can be also specified with an array that represents the coordinates of the values F along the dimensions. For instance a uniform spacing:
Or a non uniform one:
For two dimensional arrays, the return will be two arrays ordered by axis. In this example the first array stands for the gradient in rows and the second one in columns direction:
In this example the spacing is also specified: uniform for axis=0 and non uniform for axis=1
It is possible to specify how boundaries are treated using edge_order
The axis keyword can be used to specify a subset of axes of which the gradient is calculated


Return the truth value of (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.greater on ndarrays.


Return the truth value of (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.greater_equal on ndarrays.


Half-precision floating-point number type.
'e'
numpy.float16: 16-bit-precision floating-point number type: sign bit, 5 bits exponent, 10 bits mantissa.


Return the Hamming window.
The Hamming window is a taper formed by using a weighted cosine.
Number of points in the output window. If zero or less, an empty array is returned.
The window, with the maximum value normalized to one (the value one appears only if the number of samples is odd).
See also
The Hamming window is defined as
The Hamming was named for R. W. Hamming, an associate of J. W. Tukey and is described in Blackman and Tukey. It was recommended for smoothing the truncated autocovariance function in the time domain. Most references to the Hamming window come from the signal processing literature, where it is used as one of many windowing functions for smoothing values. It is also known as an apodization (which means “removing the foot”, i.e. smoothing discontinuities at the beginning and end of the sampled signal) or tapering function.
Blackman, R.B. and Tukey, J.W., (1958) The measurement of power spectra, Dover Publications, New York.
E.R. Kanasewich, “Time Sequence Analysis in Geophysics”, The University of Alberta Press, 1975, pp. 109-110.
Wikipedia, “Window function”, https://en.wikipedia.org/wiki/Window_function
W.H. Press, B.P. Flannery, S.A. Teukolsky, and W.T. Vetterling, “Numerical Recipes”, Cambridge University Press, 1986, page 425.
Plot the window and the frequency response:


Return the Hanning window.
The Hanning window is a taper formed by using a weighted cosine.
Number of points in the output window. If zero or less, an empty array is returned.
The window, with the maximum value normalized to one (the value one appears only if M is odd).
See also
The Hanning window is defined as
The Hanning was named for Julius von Hann, an Austrian meteorologist. It is also known as the Cosine Bell. Some authors prefer that it be called a Hann window, to help avoid confusion with the very similar Hamming window.
Most references to the Hanning window come from the signal processing literature, where it is used as one of many windowing functions for smoothing values. It is also known as an apodization (which means “removing the foot”, i.e. smoothing discontinuities at the beginning and end of the sampled signal) or tapering function.
Blackman, R.B. and Tukey, J.W., (1958) The measurement of power spectra, Dover Publications, New York.
E.R. Kanasewich, “Time Sequence Analysis in Geophysics”, The University of Alberta Press, 1975, pp. 106-108.
Wikipedia, “Window function”, https://en.wikipedia.org/wiki/Window_function
W.H. Press, B.P. Flannery, S.A. Teukolsky, and W.T. Vetterling, “Numerical Recipes”, Cambridge University Press, 1986, page 425.
Plot the window and its frequency response:


Compute the Heaviside step function.
The Heaviside step function is defined as:
where x2 is often taken to be 0.5, but 0 and 1 are also sometimes used.
Input values.
The value of the function when x1 is 0. 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 output array, element-wise Heaviside step function of x1. This is a scalar if both x1 and x2 are scalars.
New in version 1.13.0.


Compute the histogram of a dataset.
Input data. The histogram is computed over the flattened array.
If bins is an int, it defines the number of equal-width bins in the given range (10, by default). If bins is a sequence, it defines a monotonically increasing array of bin edges, including the rightmost edge, allowing for non-uniform bin widths.
New in version 1.11.0.
If bins is a string, it defines the method used to calculate the optimal bin width, as defined by histogram_bin_edges.
The lower and upper range of the bins. If not provided, range is simply (a.min(), a.max()). Values outside the range are ignored. The first element of the range must be less than or equal to the second. range affects the automatic bin computation as well. While bin width is computed to be optimal based on the actual data within range, the bin count will fill the entire range including portions containing no data.
Deprecated since version 1.6.0.
This is equivalent to the density argument, but produces incorrect results for unequal bin widths. It should not be used.
Changed in version 1.15.0: DeprecationWarnings are actually emitted.
An array of weights, of the same shape as a. Each value in a only contributes its associated weight towards the bin count (instead of 1). If density is True, the weights are normalized, so that the integral of the density over the range remains 1.
If False, the result will contain the number of samples in each bin. If True, the result is the value of the probability density function at the bin, normalized such that the integral over the range is 1. Note that the sum of the histogram values will not be equal to 1 unless bins of unity width are chosen; it is not a probability mass function.
Overrides the normed keyword if given.
The values of the histogram. See density and weights for a description of the possible semantics.
Return the bin edges (length(hist)+1).
See also
All but the last (righthand-most) bin is half-open. In other words, if bins is:
then the first bin is [1, 2) (including 1, but excluding 2) and the second [2, 3). The last bin, however, is [3, 4], which includes 4.
New in version 1.11.0.
Automated Bin Selection Methods example, using 2 peak random data with 2000 points:


Compute the bi-dimensional histogram of two data samples.
An array containing the x coordinates of the points to be histogrammed.
An array containing the y coordinates of the points to be histogrammed.
The bin specification:
The leftmost and rightmost edges of the bins along each dimension (if not specified explicitly in the bins parameters): [[xmin, xmax], [ymin, ymax]]. All values outside of this range will be considered outliers and not tallied in the histogram.
If False, the default, returns the number of samples in each bin. If True, returns the probability density function at the bin, bin_count / sample_count / bin_area.
An alias for the density argument that behaves identically. To avoid confusion with the broken normed argument to histogram, density should be preferred.
An array of values w_i weighing each sample (x_i, y_i). Weights are normalized to 1 if normed is True. If normed is False, the values of the returned histogram are equal to the sum of the weights belonging to the samples falling into each bin.
The bi-dimensional histogram of samples x and y. Values in x are histogrammed along the first dimension and values in y are histogrammed along the second dimension.
The bin edges along the first dimension.
The bin edges along the second dimension.
See also
1D histogram
Multidimensional histogram
When normed is True, then the returned histogram is the sample density, defined such that the sum over bins of the product bin_value * bin_area is 1.
Please note that the histogram does not follow the Cartesian convention where x values are on the abscissa and y values on the ordinate axis. Rather, x is histogrammed along the first dimension of the array (vertical), and y along the second dimension of the array (horizontal). This ensures compatibility with histogramdd.
Construct a 2-D histogram with variable bin width. First define the bin edges:
Next we create a histogram H with random bin content:
imshow can only display square bins:
pcolormesh can display actual edges:
NonUniformImage can be used to display actual bin edges with interpolation:
It is also possible to construct a 2-D histogram without specifying bin edges:
Now we can plot the histogram using pcolormesh, and a hexbin for comparison.


Function to calculate only the edges of the bins used by the histogram function.
Input data. The histogram is computed over the flattened array.
If bins is an int, it defines the number of equal-width bins in the given range (10, by default). If bins is a sequence, it defines the bin edges, including the rightmost edge, allowing for non-uniform bin widths.
If bins is a string from the list below, histogram_bin_edges will use the method chosen to calculate the optimal bin width and consequently the number of bins (see Notes for more detail on the estimators) from the data that falls within the requested range. While the bin width will be optimal for the actual data in the range, the number of bins will be computed to fill the entire range, including the empty portions. For visualisation, using the ‘auto’ option is suggested. Weighted data is not supported for automated bin size selection.
Maximum of the ‘sturges’ and ‘fd’ estimators. Provides good all around performance.
Robust (resilient to outliers) estimator that takes into account data variability and data size.
An improved version of Sturges’ estimator that works better with non-normal datasets.
Less robust estimator that that takes into account data variability and data size.
Estimator based on leave-one-out cross-validation estimate of the integrated squared error. Can be regarded as a generalization of Scott’s rule.
Estimator does not take variability into account, only data size. Commonly overestimates number of bins required.
R’s default method, only accounts for data size. Only optimal for gaussian data and underestimates number of bins for large non-gaussian datasets.
Square root (of data size) estimator, used by Excel and other programs for its speed and simplicity.
The lower and upper range of the bins. If not provided, range is simply (a.min(), a.max()). Values outside the range are ignored. The first element of the range must be less than or equal to the second. range affects the automatic bin computation as well. While bin width is computed to be optimal based on the actual data within range, the bin count will fill the entire range including portions containing no data.
An array of weights, of the same shape as a. Each value in a only contributes its associated weight towards the bin count (instead of 1). This is currently not used by any of the bin estimators, but may be in the future.
The edges to pass into histogram
See also
The methods to estimate the optimal number of bins are well founded in literature, and are inspired by the choices R provides for histogram visualisation. Note that having the number of bins proportional to \(n^{1/3}\) is asymptotically optimal, which is why it appears in most estimators. These are simply plug-in methods that give good starting points for number of bins. In the equations below, \(h\) is the binwidth and \(n_h\) is the number of bins. All estimators that compute bin counts are recast to bin width using the ptp of the data. The final bin count is obtained from np.round(np.ceil(range / h)). The final bin width is often less than what is returned by the estimators below.
A compromise to get a good value. For small datasets the Sturges value will usually be chosen, while larger datasets will usually default to FD. Avoids the overly conservative behaviour of FD and Sturges for small and large datasets respectively. Switchover point is usually \(a.size \approx 1000\).
The binwidth is proportional to the interquartile range (IQR) and inversely proportional to cube root of a.size. Can be too conservative for small datasets, but is quite good for large datasets. The IQR is very robust to outliers.
The binwidth is proportional to the standard deviation of the data and inversely proportional to cube root of x.size. Can be too conservative for small datasets, but is quite good for large datasets. The standard deviation is not very robust to outliers. Values are very similar to the Freedman-Diaconis estimator in the absence of outliers.
The number of bins is only proportional to cube root of a.size. It tends to overestimate the number of bins and it does not take into account data variability.
The number of bins is the base 2 log of a.size. This estimator assumes normality of data and is too conservative for larger, non-normal datasets. This is the default method in R’s hist method.
An improved version of Sturges’ formula that produces better estimates for non-normal datasets. This estimator attempts to account for the skew of the data.
The simplest and fastest estimator. Only takes into account the data size.
For consistency with histogram, an array of pre-computed bins is passed through unmodified:
This function allows one set of bins to be computed, and reused across multiple histograms:
Which gives more easily comparable results than using separate bins for each histogram:


Compute the multidimensional histogram of some data.
The data to be histogrammed.
Note the unusual interpretation of sample when an array_like:
The first form should be preferred.
The bin specification:
A sequence of length D, each an optional (lower, upper) tuple giving the outer bin edges to be used if the edges are not given explicitly in bins. An entry of None in the sequence results in the minimum and maximum values being used for the corresponding dimension. The default, None, is equivalent to passing a tuple of D None values.
If False, the default, returns the number of samples in each bin. If True, returns the probability density function at the bin, bin_count / sample_count / bin_volume.
An alias for the density argument that behaves identically. To avoid confusion with the broken normed argument to histogram, density should be preferred.
An array of values w_i weighing each sample (x_i, y_i, z_i, …). Weights are normalized to 1 if normed is True. If normed is False, the values of the returned histogram are equal to the sum of the weights belonging to the samples falling into each bin.
The multidimensional histogram of sample x. See normed and weights for the different possible semantics.
A list of D arrays describing the bin edges for each dimension.
See also
1-D histogram
2-D histogram


Split an array into multiple sub-arrays horizontally (column-wise).
Please refer to the split documentation. hsplit is equivalent to split with axis=1, the array is always split along the second axis regardless of the array dimension.
See also
Split an array into multiple sub-arrays of equal size.
With a higher dimensional array the split is still along the second axis.


Stack arrays in sequence horizontally (column wise).
This is equivalent to concatenation along the second axis, except for 1-D arrays where it concatenates along the first axis. Rebuilds arrays divided by hsplit.
This function makes most sense for arrays with up to 3 dimensions. For instance, for pixel-data with a height (first axis), width (second axis), and r/g/b channels (third axis). The functions concatenate, stack and block provide more general stacking and concatenation operations.
The arrays must have the same shape along all but the second axis, except 1-D arrays which can be any length.
The array formed by stacking the given arrays.
See also
Join a sequence of arrays along an existing axis.
Join a sequence of arrays along a new axis.
Assemble an nd-array from nested lists of blocks.
Stack arrays in sequence vertically (row wise).
Stack arrays in sequence depth wise (along third axis).
Stack 1-D arrays as columns into a 2-D array.
Split an array into multiple sub-arrays horizontally (column-wise).


Given the “legs” of a right triangle, return its hypotenuse.
Equivalent to sqrt(x1**2 + x2**2), element-wise. If x1 or x2 is scalar_like (i.e., unambiguously cast-able to a scalar type), it is broadcast for use with each element of the other argument. (See Examples)
Leg of the triangle(s). 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 hypotenuse of the triangle(s). This is a scalar if both x1 and x2 are scalars.
Example showing broadcast of scalar_like argument:


Modified Bessel function of the first kind, order 0.
Usually denoted \(I_0\).
Argument of the Bessel function.
The modified Bessel function evaluated at each of the elements of x.
See also
The scipy implementation is recommended over this function: it is a proper ufunc written in C, and more than an order of magnitude faster.
We use the algorithm published by Clenshaw [1] and referenced by Abramowitz and Stegun [2], for which the function domain is partitioned into the two intervals [0,8] and (8,inf), and Chebyshev polynomial expansions are employed in each interval. Relative error on the domain [0,30] using IEEE arithmetic is documented [3] as having a peak of 5.8e-16 with an rms of 1.4e-16 (n = 30000).
C. W. Clenshaw, “Chebyshev series for mathematical functions”, in National Physical Laboratory Mathematical Tables, vol. 5, London: Her Majesty’s Stationery Office, 1962.
M. Abramowitz and I. A. Stegun, Handbook of Mathematical Functions, 10th printing, New York: Dover, 1964, pp. 379. https://personal.math.ubc.ca/~cbm/aands/page_379.htm
https://metacpan.org/pod/distribution/Math-Cephes/lib/Math/Cephes.pod#i0:-Modified-Bessel-function-of-order-zero


Return the identity array.
The identity array is a square array with ones on the main diagonal.
Number of rows (and columns) in n x n output.
Data-type of the output. Defaults to float.
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.
n x n array with its main diagonal set to one, and all other elements 0.


Machine limits for integer types.
The kind of integer data type to get information about.
See also
The equivalent for floating point data types.
With types:
With instances:
The number of bits occupied by the type.
Minimum value of given dtype.
Maximum value of given dtype.


Return the imaginary part of the complex argument.
Input array.
The imaginary component of the complex argument. If val is real, the type of val is used for the output. If val has complex elements, the returned type is float.
See also


Test whether each element of a 1-D array is also present in a second array.
Returns a boolean array the same length as ar1 that is True where an element of ar1 is in ar2 and False otherwise.
We recommend using isin instead of in1d for new code.
Input array.
The values against which to test each value of ar1.
If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False.
If True, the values in the returned array are inverted (that is, False where an element of ar1 is in ar2 and True otherwise). Default is False. np.in1d(a, b, invert=True) is equivalent to (but is faster than) np.invert(in1d(a, b)).
New in version 1.8.0.
The values ar1[in1d] are in ar2.
See also
Version of this function that preserves the shape of ar1.
Module with a number of other functions for performing set operations on arrays.
in1d can be considered as an element-wise function version of the python keyword in, for 1-D sequences. in1d(a, b) is roughly equivalent to np.array([item in b for item in a]). However, this idea fails if ar2 is a set, or similar (non-sequence) container: As ar2 is converted to an array, in those cases asarray(ar2) is an object array rather than the expected array of contained values.
New in version 1.4.0.


Return an array representing the indices of a grid.
Compute an array where the subarrays contain index values 0, 1, … varying only along the corresponding axis.
The shape of the grid.
Data type of the result.
Return a sparse representation of the grid instead of a dense representation. Default is False.
New in version 1.17.
Returns one array of grid indices, grid.shape = (len(dimensions),) + tuple(dimensions).
Returns a tuple of arrays, with grid[i].shape = (1, ..., 1, dimensions[i], 1, ..., 1) with dimensions[i] in the ith place
See also
The output shape in the dense case is obtained by prepending the number of dimensions in front of the tuple of dimensions, i.e. if dimensions is a tuple (r0, ..., rN-1) of length N, the output shape is (N, r0, ..., rN-1).
The subarrays grid[k] contains the N-D array of indices along the k-th axis. Explicitly:
The indices can be used as an index into an array.
Note that it would be more straightforward in the above example to extract the required elements directly with x[:2, :3].
If sparse is set to true, the grid will be returned in a sparse representation.


NumPy includes several constants:
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
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
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 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.
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.
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 (positive) infinity.
Use inf because Inf, Infinity, PINF and infty are aliases for inf. For more details, see inf.
inf
IEEE 754 floating point representation of positive zero.
A floating point representation of positive zero.
NZERO : Defines negative 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). Positive zero is considered to be a finite number.
Euler’s constant, base of natural logarithms, Napier’s constant.
e = 2.71828182845904523536028747135266249775724709369995...
exp : Exponential function log : Natural logarithm
https://en.wikipedia.org/wiki/E_%28mathematical_constant%29
γ = 0.5772156649015328606065120900824024310421...
https://en.wikipedia.org/wiki/Euler-Mascheroni_constant
IEEE 754 floating point representation of (positive) infinity.
A floating point representation of positive 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.
Inf, Infinity, PINF and infty are aliases for inf.
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
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.
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]:
pi = 3.1415926535897932384626433...
https://en.wikipedia.org/wiki/Pi


IEEE 754 floating point representation of (positive) infinity.
A floating point representation of positive 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.
Inf, Infinity, PINF and infty are aliases for inf.


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


Get help information for a function, class, or module.
Input object or name to get information about. If object is a numpy object, its docstring is given. If it is a string, available modules are searched for matching objects. If None, information about info itself is returned.
Printing width.
File like object that the output is written to, default is stdout. The object has to be opened in ‘w’ or ‘a’ mode.
Start search at this level.
See also
When used interactively with an object, np.info(obj) is equivalent to help(obj) on the Python prompt or obj? on the IPython prompt.
When using a string for object it is possible to get multiple results.


Inner product of two arrays.
Ordinary inner product of vectors for 1-D arrays (without complex conjugation), in higher dimensions a sum product over the last axes.
If a and b are nonscalar, their last dimensions must match.
If a and b are both scalars or both 1-D arrays then a scalar is returned; otherwise an array is returned. out.shape = (*a.shape[:-1], *b.shape[:-1])
If both a and b are nonscalar and their last dimensions have different sizes.
See also
Sum products over arbitrary axes.
Generalised matrix product, using second last dimension of b.
Einstein summation convention.
For vectors (1-D arrays) it computes the ordinary inner-product:
More generally, if ndim(a) = r > 0 and ndim(b) = s > 0:
or explicitly:
In addition a or b may be scalars, in which case:
Ordinary inner product for vectors:
Some multidimensional examples:
An example where b is a scalar:


Insert values along the given axis before the given indices.
Input array.
Object that defines the index or indices before which values is inserted.
New in version 1.8.0.
Support for multiple insertions when obj is a single scalar or a sequence with one element (similar to calling insert multiple times).
Values to insert into arr. If the type of values is different from that of arr, values is converted to the type of arr. values should be shaped so that arr[...,obj,...] = values is legal.
Axis along which to insert values. If axis is None then arr is flattened first.
A copy of arr with values inserted. Note that insert does not occur in-place: a new array is returned. If axis is None, out is a flattened array.
See also
Append elements at the end of an array.
Join a sequence of arrays along an existing axis.
Delete elements from an array.
Note that for higher dimensional inserts obj=0 behaves very different from obj=[0] just like arr[:,0,:] = values is different from arr[:,[0],:] = values.
Difference between sequence and scalars:


Aliases for the signed integer types (one of numpy.byte, numpy.short, numpy.intc, numpy.int_ and numpy.longlong) with the specified number of bits.
Compatible with the C99 int8_t, int16_t, int32_t, and int64_t, respectively.


Signed integer type, compatible with Python int and C long.
'l'
numpy.int64: 64-bit signed integer (-9_223_372_036_854_775_808 to 9_223_372_036_854_775_807).
numpy.intp: Signed integer large enough to fit pointer, compatible with C intptr_t.


Signed integer type, compatible with C int.
'i'
numpy.int32: 32-bit signed integer (-2_147_483_648 to 2_147_483_647).


One-dimensional linear interpolation for monotonically increasing sample points.
Returns the one-dimensional piecewise linear interpolant to a function with given discrete data points (xp, fp), evaluated at x.
The x-coordinates at which to evaluate the interpolated values.
The x-coordinates of the data points, must be increasing if argument period is not specified. Otherwise, xp is internally sorted after normalizing the periodic boundaries with xp = xp % period.
The y-coordinates of the data points, same length as xp.
Value to return for x < xp[0], default is fp[0].
Value to return for x > xp[-1], default is fp[-1].
A period for the x-coordinates. This parameter allows the proper interpolation of angular x-coordinates. Parameters left and right are ignored if period is specified.
New in version 1.10.0.
The interpolated values, same shape as x.
If xp and fp have different length If xp or fp are not 1-D sequences If period == 0
Warning
The x-coordinate sequence is expected to be increasing, but this is not explicitly enforced. However, if the sequence xp is non-increasing, interpolation results are meaningless.
Note that, since NaN is unsortable, xp also cannot contain NaNs.
A simple check for xp being strictly increasing is:
See also
Plot an interpolant to the sine function:
Interpolation with periodic x-coordinates:
Complex interpolation:


Find the intersection of two arrays.
Return the sorted, unique values that are in both of the input arrays.
Input arrays. Will be flattened if not already 1D.
If True, the input arrays are both assumed to be unique, which can speed up the calculation. If True but ar1 or ar2 are not unique, incorrect results and out-of-bounds indices could result. Default is False.
If True, the indices which correspond to the intersection of the two arrays are returned. The first instance of a value is used if there are multiple. Default is False.
New in version 1.15.0.
Sorted 1D array of common and unique elements.
The indices of the first occurrences of the common values in ar1. Only provided if return_indices is True.
The indices of the first occurrences of the common values in ar2. Only provided if return_indices is True.
See also
Module with a number of other functions for performing set operations on arrays.
To intersect more than two arrays, use functools.reduce:
To return the indices of the values common to the input arrays along with the intersected values:


Alias for the signed integer type (one of numpy.byte, numpy.short, numpy.intc, numpy.int_ and np.longlong) that is the same size as a pointer.
Compatible with the C intptr_t.
'p'


Compute bit-wise inversion, or bit-wise NOT, element-wise.
Computes the bit-wise NOT of the underlying binary representation of the integers in the input arrays. This ufunc implements the C/Python operator ~.
For signed integer inputs, the two’s complement is returned. In a two’s-complement system negative numbers are represented by the two’s complement of the absolute value. This is the most common method of representing signed integers on computers [1]. A N-bit two’s-complement system can represent every integer in the range \(-2^{N-1}\) to \(+2^{N-1}-1\).
Only integer and boolean types are handled.
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.
Result. This is a scalar if x is a scalar.
See also
Return the binary representation of the input number as a string.
bitwise_not is an alias for invert:
Wikipedia, “Two’s complement”, https://en.wikipedia.org/wiki/Two’s_complement
We’ve seen that 13 is represented by 00001101. The invert or bit-wise NOT of 13 is then:
The result depends on the bit-width:
When using signed integer types the result is the two’s complement of the result for the unsigned type:
Booleans are accepted as well:
The ~ operator can be used as a shorthand for np.invert on ndarrays.


Calculates which of the given dates are valid days, and which are not.
New in version 1.7.0.
The array of dates to process.
A seven-element array indicating which of Monday through Sunday are valid days. May be specified as a length-seven list or array, like [1,1,1,1,1,0,0]; a length-seven string, like ‘1111100’; or a string like “Mon Tue Wed Thu Fri”, made up of 3-character abbreviations for weekdays, optionally separated by white space. Valid abbreviations are: Mon Tue Wed Thu Fri Sat Sun
An array of dates to consider as invalid dates. They may be specified in any order, and NaT (not-a-time) dates are ignored. This list is saved in a normalized form that is suited for fast calculations of valid days.
A busdaycalendar object which specifies the valid days. If this parameter is provided, neither weekmask nor holidays may be provided.
If provided, this array is filled with the result.
An array with the same shape as dates, containing True for each valid day, and False for each invalid day.
See also
An object that specifies a custom set of valid days.
Applies an offset counted in valid days.
Counts how many valid days are in a half-open date range.


Returns a boolean array where two arrays are element-wise equal within a tolerance.
The tolerance values are positive, typically very small numbers. The relative difference (rtol * abs(b)) and the absolute difference atol are added together to compare against the absolute difference between a and b.
Warning
The default atol is not appropriate for comparing numbers that are much smaller than one (see Notes).
Input arrays to compare.
The relative tolerance parameter (see Notes).
The absolute tolerance parameter (see Notes).
Whether to compare NaN’s as equal. If True, NaN’s in a will be considered equal to NaN’s in b in the output array.
Returns a boolean array of where a and b are equal within the given tolerance. If both a and b are scalars, returns a single boolean value.
See also
New in version 1.7.0.
For finite values, isclose uses the following equation to test whether two floating point values are equivalent.
absolute(a - b) <= (atol + rtol * absolute(b))
Unlike the built-in math.isclose, the above equation is not symmetric in a and b – it assumes b is the reference value – so that isclose(a, b) might be different from isclose(b, a). Furthermore, the default value of atol is not zero, and is used to determine what small values should be considered close to zero. The default value is appropriate for expected values of order unity: if the expected values are significantly smaller than one, it can result in false positives. atol should be carefully selected for the use case at hand. A zero value for atol will result in False if either a or b is zero.
isclose is not defined for non-numeric data types. bool is considered a numeric data-type for this purpose.


Returns a bool array, where True if input element is complex.
What is tested is whether the input has a non-zero imaginary part, not if the input type is complex.
Input array.
Output array.
See also
Return True if x is a complex type or an array of complex numbers.


Check for a complex type or an array of complex numbers.
The type of the input is checked, not the value. Even if the input has an imaginary part equal to zero, iscomplexobj evaluates to True.
The input can be of any type and shape.
The return value, True if x is of a complex type or has at least one complex element.
See also


Test element-wise for finiteness (not infinity and not Not a Number).
The result is returned as a boolean array.
Input values.
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.
True where x is not positive infinity, negative infinity, or NaN; false otherwise. This is a scalar if x is a scalar.
See also
Not a Number, positive infinity and negative infinity are considered to be non-finite.
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. Errors result if the second argument is also supplied when x is a scalar input, or if first and second arguments have different shapes.


Check if the array is Fortran contiguous but not C contiguous.
This function is obsolete and, because of changes due to relaxed stride checking, its return value for the same array may differ for versions of NumPy >= 1.10.0 and previous versions. If you only want to check if an array is Fortran contiguous use a.flags.f_contiguous instead.
Input array.
Returns True if the array is Fortran contiguous but not C contiguous.
np.array allows to specify whether the array is written in C-contiguous order (last index varies the fastest), or FORTRAN-contiguous order in memory (first index varies the fastest).
The transpose of a C-ordered array is a FORTRAN-ordered array.
C-ordered arrays evaluate as False even if they are also FORTRAN-ordered.


Calculates element in test_elements, broadcasting over element only. Returns a boolean array of the same shape as element that is True where an element of element is in test_elements and False otherwise.
Input array.
The values against which to test each value of element. This argument is flattened if it is an array or array_like. See notes for behavior with non-array-like parameters.
If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False.
If True, the values in the returned array are inverted, as if calculating element not in test_elements. Default is False. np.isin(a, b, invert=True) is equivalent to (but faster than) np.invert(np.isin(a, b)).
Has the same shape as element. The values element[isin] are in test_elements.
See also
Flattened version of this function.
Module with a number of other functions for performing set operations on arrays.
isin is an element-wise function version of the python keyword in. isin(a, b) is roughly equivalent to np.array([item in b for item in a]) if a and b are 1-D sequences.
element and test_elements are converted to arrays if they are not already. If test_elements is a set (or other non-sequence collection) it will be converted to an object array with one element, rather than an array of the values contained in test_elements. This is a consequence of the array constructor’s way of handling non-sequence collections. Converting the set to a list usually gives the desired behavior.
New in version 1.13.0.
The indices of the matched values can be obtained with nonzero:
The test can also be inverted:
Because of how array handles sets, the following does not work as expected:
Casting the set to a list gives the expected result:


Test element-wise for positive or negative infinity.
Returns a boolean array of the same shape as x, True where x ==
+/-inf, otherwise False.
Input values
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.
True where x is positive or negative infinity, false otherwise. This is a scalar if x is a scalar.
See also
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754).
Errors result if the second argument is supplied when the first argument is a scalar, or if the first and second arguments have different shapes.