numpy.loadtxt   numpy.loadtxt(fname, dtype=<class 'float'>, comments='#', delimiter=None, converters=None, skiprows=0, usecols=None, unpack=False, ndmin=0, encoding='bytes', max_rows=None, *, like=None)[source]

Load data from a text file. Each row in the text file must have the same number of values.  Parameters

fnamefile, str, pathlib.Path, list of str, generator

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.
dtypedata-type, optional

Data-type of the resulting array; default: float. If this is a structured data-type, the resulting array will be 1-dimensional, and each row will be interpreted as an element of the array. In this case, the number of columns used must match the number of fields in the data-type.
commentsstr or sequence of str, optional

The characters or list of characters used to indicate the start of a comment. None implies no comments. For backwards compatibility, byte strings will be decoded as ‘latin1’. The default is ‘#’.
delimiterstr, optional

The string used to separate values. For backwards compatibility, byte strings will be decoded as ‘latin1’. The default is whitespace.
convertersdict, optional

A dictionary mapping column number to a function that will parse the column string into the desired value. E.g., if column 0 is a date string: converters = {0: datestr2num}. Converters can also be used to provide a default value for missing data (but see also genfromtxt): converters = {3: lambda s: float(s.strip() or 0)}. Default: None.
skiprowsint, optional

Skip the first skiprows lines, including comments; default: 0.
usecolsint or sequence, optional

Which columns to read, with 0 being the first. For example, usecols = (1,4,5) will extract the 2nd, 5th and 6th columns. The default, None, results in all columns being read.  Changed in version 1.11.0: When a single column has to be read it is possible to use an integer instead of a tuple. E.g usecols = 3 reads the fourth column the same way as usecols = (3,) would.
unpackbool, optional

If True, the returned array is transposed, so that arguments may be unpacked using x, y, z = loadtxt(...). When used with a structured data-type, arrays are returned for each field. Default is False.
ndminint, optional

The returned array will have at least ndmin dimensions. Otherwise mono-dimensional axes will be squeezed. Legal values: 0 (default), 1 or 2.  New in version 1.6.0.
encodingstr, optional

Encoding used to decode the inputfile. Does not apply to input streams. The special value ‘bytes’ enables backward compatibility workarounds that ensures you receive byte arrays as results if 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.
max_rowsint, optional

Read max_rows lines of content after skiprows lines. The default is to read all the lines.  New in version 1.16.0.
likearray_like

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.     Returns

outndarray

Data read from the text file.      See also
load, fromstring, fromregex

genfromtxt

Load data with missing values handled as specified.  scipy.io.loadmat

reads MATLAB data files    Notes This function aims to be a fast reader for simply formatted files. The genfromtxt function provides more sophisticated handling of, e.g., lines with missing values.  New in version 1.10.0.  The strings produced by the Python float.hex method can be used as input for floats. Examples >>> from io import StringIO   # StringIO behaves like a file object
>>> c = StringIO("0 1\n2 3")
>>> np.loadtxt(c)
array([[0., 1.],
       [2., 3.]])
 >>> d = StringIO("M 21 72\nF 35 58")
>>> np.loadtxt(d, dtype={'names': ('gender', 'age', 'weight'),
...                      'formats': ('S1', 'i4', 'f4')})
array([(b'M', 21, 72.), (b'F', 35, 58.)],
      dtype=[('gender', 'S1'), ('age', '<i4'), ('weight', '<f4')])
 >>> c = StringIO("1,0,2\n3,0,4")
>>> x, y = np.loadtxt(c, delimiter=',', usecols=(0, 2), unpack=True)
>>> x
array([1., 3.])
>>> y
array([2., 4.])
 This example shows how converters can be used to convert a field with a trailing minus sign into a negative number. >>> s = StringIO('10.01 31.25-\n19.22 64.31\n17.57- 63.94')
>>> def conv(fld):
...     return -float(fld[:-1]) if fld.endswith(b'-') else float(fld)
...
>>> np.loadtxt(s, converters={0: conv, 1: conv})
array([[ 10.01, -31.25],
       [ 19.22,  64.31],
       [-17.57,  63.94]])


numpy.log   numpy.log(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'log'>

Natural logarithm, element-wise. The natural logarithm log is the inverse of the exponential function, so that log(exp(x)) = x. The natural logarithm is logarithm in base e.  Parameters

xarray_like

Input value.
outndarray, None, or tuple of ndarray and None, optional

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.
wherearray_like, optional

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.  **kwargs

For other keyword-only arguments, see the ufunc docs.    Returns

yndarray

The natural logarithm of x, element-wise. This is a scalar if x is a scalar.      See also
log10, log2, log1p, emath.log

  Notes Logarithm is a multivalued function: for each x there is an infinite number of z such that exp(z) = x. The convention is to return the z whose imaginary part lies in [-pi, pi]. For real-valued input data types, log always returns real output. For each value that cannot be expressed as a real number or infinity, it yields nan and sets the invalid floating point error flag. For complex-valued input, log is a complex analytical function that has a branch cut [-inf, 0] and is continuous from above on it. log handles the floating-point negative zero as an infinitesimal negative number, conforming to the C99 standard. References  1
M. Abramowitz and I.A. Stegun, “Handbook of Mathematical Functions”, 10th printing, 1964, pp. 67. https://personal.math.ubc.ca/~cbm/aands/page_67.htm  2
Wikipedia, “Logarithm”. https://en.wikipedia.org/wiki/Logarithm   Examples >>> np.log([1, np.e, np.e**2, 0])
array([  0.,   1.,   2., -Inf])


numpy.log10   numpy.log10(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'log10'>

Return the base 10 logarithm of the input array, element-wise.  Parameters

xarray_like

Input values.
outndarray, None, or tuple of ndarray and None, optional

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.
wherearray_like, optional

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.  **kwargs

For other keyword-only arguments, see the ufunc docs.    Returns

yndarray

The logarithm to the base 10 of x, element-wise. NaNs are returned where x is negative. This is a scalar if x is a scalar.      See also  emath.log10
  Notes Logarithm is a multivalued function: for each x there is an infinite number of z such that 10**z = x. The convention is to return the z whose imaginary part lies in [-pi, pi]. For real-valued input data types, log10 always returns real output. For each value that cannot be expressed as a real number or infinity, it yields nan and sets the invalid floating point error flag. For complex-valued input, log10 is a complex analytical function that has a branch cut [-inf, 0] and is continuous from above on it. log10 handles the floating-point negative zero as an infinitesimal negative number, conforming to the C99 standard. References  1
M. Abramowitz and I.A. Stegun, “Handbook of Mathematical Functions”, 10th printing, 1964, pp. 67. https://personal.math.ubc.ca/~cbm/aands/page_67.htm  2
Wikipedia, “Logarithm”. https://en.wikipedia.org/wiki/Logarithm   Examples >>> np.log10([1e-15, -3.])
array([-15.,  nan])


numpy.log1p   numpy.log1p(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'log1p'>

Return the natural logarithm of one plus the input array, element-wise. Calculates log(1 + x).  Parameters

xarray_like

Input values.
outndarray, None, or tuple of ndarray and None, optional

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.
wherearray_like, optional

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.  **kwargs

For other keyword-only arguments, see the ufunc docs.    Returns

yndarray

Natural logarithm of 1 + x, element-wise. This is a scalar if x is a scalar.      See also  expm1

exp(x) - 1, the inverse of log1p.    Notes For real-valued input, log1p is accurate also for x so small that 1 + x == 1 in floating-point accuracy. Logarithm is a multivalued function: for each x there is an infinite number of z such that exp(z) = 1 + x. The convention is to return the z whose imaginary part lies in [-pi, pi]. For real-valued input data types, log1p always returns real output. For each value that cannot be expressed as a real number or infinity, it yields nan and sets the invalid floating point error flag. For complex-valued input, log1p is a complex analytical function that has a branch cut [-inf, -1] and is continuous from above on it. log1p handles the floating-point negative zero as an infinitesimal negative number, conforming to the C99 standard. References  1
M. Abramowitz and I.A. Stegun, “Handbook of Mathematical Functions”, 10th printing, 1964, pp. 67. https://personal.math.ubc.ca/~cbm/aands/page_67.htm  2
Wikipedia, “Logarithm”. https://en.wikipedia.org/wiki/Logarithm   Examples >>> np.log1p(1e-99)
1e-99
>>> np.log(1 + 1e-99)
0.0


numpy.log2   numpy.log2(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'log2'>

Base-2 logarithm of x.  Parameters

xarray_like

Input values.
outndarray, None, or tuple of ndarray and None, optional

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.
wherearray_like, optional

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.  **kwargs

For other keyword-only arguments, see the ufunc docs.    Returns

yndarray

Base-2 logarithm of x. This is a scalar if x is a scalar.      See also
log, log10, log1p, emath.log2

  Notes  New in version 1.3.0.  Logarithm is a multivalued function: for each x there is an infinite number of z such that 2**z = x. The convention is to return the z whose imaginary part lies in [-pi, pi]. For real-valued input data types, log2 always returns real output. For each value that cannot be expressed as a real number or infinity, it yields nan and sets the invalid floating point error flag. For complex-valued input, log2 is a complex analytical function that has a branch cut [-inf, 0] and is continuous from above on it. log2 handles the floating-point negative zero as an infinitesimal negative number, conforming to the C99 standard. Examples >>> x = np.array([0, 1, 2, 2**4])
>>> np.log2(x)
array([-Inf,   0.,   1.,   4.])
 >>> xi = np.array([0+1.j, 1, 2+0.j, 4.j])
>>> np.log2(xi)
array([ 0.+2.26618007j,  0.+0.j        ,  1.+0.j        ,  2.+2.26618007j])


numpy.logaddexp   numpy.logaddexp(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'logaddexp'>

Logarithm of the sum of exponentiations of the inputs. Calculates log(exp(x1) + exp(x2)). This function is useful in statistics where the calculated probabilities of events may be so small as to exceed the range of normal floating point numbers. In such cases the logarithm of the calculated probability is stored. This function allows adding probabilities stored in such a fashion.  Parameters

x1, x2array_like

Input values. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).
outndarray, None, or tuple of ndarray and None, optional

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.
wherearray_like, optional

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.  **kwargs

For other keyword-only arguments, see the ufunc docs.    Returns

resultndarray

Logarithm of exp(x1) + exp(x2). This is a scalar if both x1 and x2 are scalars.      See also  logaddexp2

Logarithm of the sum of exponentiations of inputs in base 2.    Notes  New in version 1.3.0.  Examples >>> prob1 = np.log(1e-50)
>>> prob2 = np.log(2.5e-50)
>>> prob12 = np.logaddexp(prob1, prob2)
>>> prob12
-113.87649168120691
>>> np.exp(prob12)
3.5000000000000057e-50


numpy.logaddexp2   numpy.logaddexp2(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'logaddexp2'>

Logarithm of the sum of exponentiations of the inputs in base-2. Calculates log2(2**x1 + 2**x2). This function is useful in machine learning when the calculated probabilities of events may be so small as to exceed the range of normal floating point numbers. In such cases the base-2 logarithm of the calculated probability can be used instead. This function allows adding probabilities stored in such a fashion.  Parameters

x1, x2array_like

Input values. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).
outndarray, None, or tuple of ndarray and None, optional

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.
wherearray_like, optional

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.  **kwargs

For other keyword-only arguments, see the ufunc docs.    Returns

resultndarray

Base-2 logarithm of 2**x1 + 2**x2. This is a scalar if both x1 and x2 are scalars.      See also  logaddexp

Logarithm of the sum of exponentiations of the inputs.    Notes  New in version 1.3.0.  Examples >>> prob1 = np.log2(1e-50)
>>> prob2 = np.log2(2.5e-50)
>>> prob12 = np.logaddexp2(prob1, prob2)
>>> prob1, prob2, prob12
(-166.09640474436813, -164.77447664948076, -164.28904982231052)
>>> 2**prob12
3.4999999999999914e-50


numpy.logical_and   numpy.logical_and(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'logical_and'>

Compute the truth value of x1 AND x2 element-wise.  Parameters

x1, x2array_like

Input arrays. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).
outndarray, None, or tuple of ndarray and None, optional

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.
wherearray_like, optional

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.  **kwargs

For other keyword-only arguments, see the ufunc docs.    Returns

yndarray or bool

Boolean result of the logical AND operation applied to the elements of x1 and x2; the shape is determined by broadcasting. This is a scalar if both x1 and x2 are scalars.      See also
logical_or, logical_not, logical_xor

bitwise_and
  Examples >>> np.logical_and(True, False)
False
>>> np.logical_and([True, False], [False, False])
array([False, False])
 >>> x = np.arange(5)
>>> np.logical_and(x>1, x<4)
array([False, False,  True,  True, False])
 The & operator can be used as a shorthand for np.logical_and on boolean ndarrays. >>> a = np.array([True, False])
>>> b = np.array([False, False])
>>> a & b
array([False, False])


numpy.logical_not   numpy.logical_not(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'logical_not'>

Compute the truth value of NOT x element-wise.  Parameters

xarray_like

Logical NOT is applied to the elements of x.
outndarray, None, or tuple of ndarray and None, optional

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.
wherearray_like, optional

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.  **kwargs

For other keyword-only arguments, see the ufunc docs.    Returns

ybool or ndarray of bool

Boolean result with the same shape as x of the NOT operation on elements of x. This is a scalar if x is a scalar.      See also
logical_and, logical_or, logical_xor

  Examples >>> np.logical_not(3)
False
>>> np.logical_not([True, False, 0, 1])
array([False,  True,  True, False])
 >>> x = np.arange(5)
>>> np.logical_not(x<3)
array([False, False, False,  True,  True])


numpy.logical_or   numpy.logical_or(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'logical_or'>

Compute the truth value of x1 OR x2 element-wise.  Parameters

x1, x2array_like

Logical OR is applied to the elements of x1 and x2. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).
outndarray, None, or tuple of ndarray and None, optional

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.
wherearray_like, optional

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.  **kwargs

For other keyword-only arguments, see the ufunc docs.    Returns

yndarray or bool

Boolean result of the logical OR operation applied to the elements of x1 and x2; the shape is determined by broadcasting. This is a scalar if both x1 and x2 are scalars.      See also
logical_and, logical_not, logical_xor

bitwise_or
  Examples >>> np.logical_or(True, False)
True
>>> np.logical_or([True, False], [False, False])
array([ True, False])
 >>> x = np.arange(5)
>>> np.logical_or(x < 1, x > 3)
array([ True, False, False, False,  True])
 The | operator can be used as a shorthand for np.logical_or on boolean ndarrays. >>> a = np.array([True, False])
>>> b = np.array([False, False])
>>> a | b
array([ True, False])


numpy.logical_xor   numpy.logical_xor(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'logical_xor'>

Compute the truth value of x1 XOR x2, element-wise.  Parameters

x1, x2array_like

Logical XOR is applied to the elements of x1 and x2. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).
outndarray, None, or tuple of ndarray and None, optional

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.
wherearray_like, optional

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.  **kwargs

For other keyword-only arguments, see the ufunc docs.    Returns

ybool or ndarray of bool

Boolean result of the logical XOR operation applied to the elements of x1 and x2; the shape is determined by broadcasting. This is a scalar if both x1 and x2 are scalars.      See also
logical_and, logical_or, logical_not, bitwise_xor

  Examples >>> np.logical_xor(True, False)
True
>>> np.logical_xor([True, True, False, False], [True, False, True, False])
array([False,  True,  True, False])
 >>> x = np.arange(5)
>>> np.logical_xor(x < 1, x > 3)
array([ True, False, False, False,  True])
 Simple example showing support of broadcasting >>> np.logical_xor(0, np.eye(2))
array([[ True, False],
       [False,  True]])


numpy.logspace   numpy.logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None, axis=0)[source]

Return numbers spaced evenly on a log scale. In linear space, the sequence starts at base ** start (base to the power of start) and ends with base ** stop (see endpoint below).  Changed in version 1.16.0: Non-scalar start and stop are now supported.   Parameters

startarray_like

base ** start is the starting value of the sequence.
stoparray_like

base ** stop is 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.
numinteger, optional

Number of samples to generate. Default is 50.
endpointboolean, optional

If true, stop is the last sample. Otherwise, it is not included. Default is True.
basearray_like, optional

The base of the log space. The step size between the elements in ln(samples) / ln(base) (or log_base(samples)) is uniform. Default is 10.0.
dtypedtype

The type of the output array. If dtype is not given, the data type is inferred from start and stop. The inferred type will never be an integer; float is chosen even if the arguments would produce an array of integers.
axisint, optional

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.     Returns

samplesndarray

num samples, equally spaced on a log scale.      See also  arange

Similar to linspace, with the step size specified instead of the number of samples. Note that, when used with a float endpoint, the endpoint may or may not be included.  linspace

Similar to logspace, but with the samples uniformly distributed in linear space, instead of log space.  geomspace

Similar to logspace, but with endpoints specified directly.    Notes Logspace is equivalent to the code >>> y = np.linspace(start, stop, num=num, endpoint=endpoint)
...
>>> power(base, y).astype(dtype)
...
 Examples >>> np.logspace(2.0, 3.0, num=4)
array([ 100.        ,  215.443469  ,  464.15888336, 1000.        ])
>>> np.logspace(2.0, 3.0, num=4, endpoint=False)
array([100.        ,  177.827941  ,  316.22776602,  562.34132519])
>>> np.logspace(2.0, 3.0, num=4, base=2.0)
array([4.        ,  5.0396842 ,  6.34960421,  8.        ])
 Graphical illustration: >>> import matplotlib.pyplot as plt
>>> N = 10
>>> x1 = np.logspace(0.1, 1, N, endpoint=True)
>>> x2 = np.logspace(0.1, 1, N, endpoint=False)
>>> y = np.zeros(N)
>>> plt.plot(x1, y, 'o')
[<matplotlib.lines.Line2D object at 0x...>]
>>> plt.plot(x2, y + 0.5, 'o')
[<matplotlib.lines.Line2D object at 0x...>]
>>> plt.ylim([-0.5, 1])
(-0.5, 1)
>>> plt.show()


numpy.longcomplex[source]

alias of numpy.clongdouble


class numpy.longdouble[source]

Extended-precision floating-point number type, compatible with C long double but not necessarily with IEEE 754 quadruple-precision.  Character code
'g'  Alias
numpy.longfloat  Alias on this platform (Linux x86_64)
numpy.float128: 128-bit extended-precision floating-point number type.


numpy.longfloat[source]

alias of numpy.longdouble


class numpy.longlong[source]

Signed integer type, compatible with C long long.  Character code
'q'


numpy.lookfor   numpy.lookfor(what, module=None, import_modules=True, regenerate=False, output=None)[source]

Do a keyword search on docstrings. A list of objects that matched the search is displayed, sorted by relevance. All given keywords need to be found in the docstring for it to be returned as a result, but the order does not matter.  Parameters

whatstr

String containing words to look for.
modulestr or list, optional

Name of module(s) whose docstrings to go through.
import_modulesbool, optional

Whether to import sub-modules in packages. Default is True.
regeneratebool, optional

Whether to re-generate the docstring cache. Default is False.
outputfile-like, optional

File-like object to write the output to. If omitted, use a pager.      See also
source, info

  Notes Relevance is determined only roughly, by checking if the keywords occur in the function name, at the start of a docstring, etc. Examples >>> np.lookfor('binary representation')
Search results for 'binary representation'
------------------------------------------
numpy.binary_repr
    Return the binary representation of the input number as a string.
numpy.core.setup_common.long_double_representation
    Given a binary dump as given by GNU od -b, look for long double
numpy.base_repr
    Return a string representation of a number in the given base system.
...


Constants of the numpy.ma module In addition to the MaskedArray class, the numpy.ma module defines several constants.   numpy.ma.masked

The masked constant is a special case of MaskedArray, with a float datatype and a null shape. It is used to test whether a specific entry of a masked array is masked, or to mask one or several entries of a masked array: >>> x = ma.array([1, 2, 3], mask=[0, 1, 0])
>>> x[1] is ma.masked
True
>>> x[-1] = ma.masked
>>> x
masked_array(data=[1, --, --],
             mask=[False,  True,  True],
       fill_value=999999)

   numpy.ma.nomask

Value indicating that a masked array has no invalid entry. nomask is used internally to speed up computations when the mask is not needed. It is represented internally as np.False_.
   numpy.ma.masked_print_options

String used in lieu of missing data when a masked array is printed. By default, this string is '--'.


numpy.ma.masked_array   numpy.ma.masked_array[source]

alias of numpy.ma.core.MaskedArray


numpy.ma.masked_print_options

String used in lieu of missing data when a masked array is printed. By default, this string is '--'.


numpy.ma.MaskType   numpy.ma.MaskType[source]

alias of numpy.bool_


numpy.ma.nomask

Value indicating that a masked array has no invalid entry. nomask is used internally to speed up computations when the mask is not needed. It is represented internally as np.False_.


numpy.MachAr   class numpy.MachAr(float_conv=<class 'float'>, int_conv=<class 'int'>, float_to_float=<class 'float'>, float_to_str=<function MachAr.<lambda>>, title='Python floating point number')[source]

Diagnosing machine parameters.  Parameters

float_convfunction, optional

Function that converts an integer or integer array to a float or float array. Default is float.
int_convfunction, optional

Function that converts a float or float array to an integer or integer array. Default is int.
float_to_floatfunction, optional

Function that converts a float array to float. Default is float. Note that this does not seem to do anything useful in the current implementation.
float_to_strfunction, optional

Function that converts a single float to a string. Default is lambda v:'%24.16e' %v.
titlestr, optional

Title that is printed in the string representation of MachAr.      See also  finfo

Machine limits for floating point types.  iinfo

Machine limits for integer types.    References  1
Press, Teukolsky, Vetterling and Flannery, “Numerical Recipes in C++,” 2nd ed, Cambridge University Press, 2002, p. 31.    Attributes

ibetaint

Radix in which numbers are represented.
itint

Number of base-ibeta digits in the floating point mantissa M.
machepint

Exponent of the smallest (most negative) power of ibeta that, added to 1.0, gives something different from 1.0
epsfloat

Floating-point number beta**machep (floating point precision)
negepint

Exponent of the smallest power of ibeta that, subtracted from 1.0, gives something different from 1.0.
epsnegfloat

Floating-point number beta**negep.
iexpint

Number of bits in the exponent (including its sign and bias).
minexpint

Smallest (most negative) power of ibeta consistent with there being no leading zeros in the mantissa.
xminfloat

Floating-point number beta**minexp (the smallest [in magnitude] positive floating point number with full precision).
maxexpint

Smallest (positive) power of ibeta that causes overflow.
xmaxfloat

(1-epsneg) * beta**maxexp (the largest [in magnitude] usable floating value).
irndint

In range(6), information on what kind of rounding is done in addition, and on how underflow is handled.
ngrdint

Number of ‘guard digits’ used when truncating the product of two mantissas to fit the representation.
epsilonfloat

Same as eps.
tinyfloat

An alias for smallest_normal, kept for backwards compatibility.
hugefloat

Same as xmax.
precisionfloat

- int(-log10(eps))
resolutionfloat

- 10**(-precision)
smallest_normalfloat

The smallest positive floating point number with 1 as leading bit in the mantissa following IEEE-754. Same as xmin.
smallest_subnormalfloat

The smallest positive floating point number with 0 as leading bit in the mantissa following IEEE-754.


numpy.mask_indices   numpy.mask_indices(n, mask_func, k=0)[source]

Return the indices to access (n, n) arrays, given a masking function. Assume mask_func is a function that, for a square array a of size (n, n) with a possible offset argument k, when called as mask_func(a, k) returns a new array with zeros in certain locations (functions like triu or tril do precisely this). Then this function returns the indices where the non-zero values would be located.  Parameters

nint

The returned indices will be valid to access arrays of shape (n, n).
mask_funccallable

A function whose call signature is similar to that of triu, tril. That is, mask_func(x, k) returns a boolean array, shaped like x. k is an optional argument to the function.
kscalar

An optional argument which is passed through to mask_func. Functions like triu, tril take a second argument that is interpreted as an offset.    Returns

indicestuple of arrays.

The n arrays of indices corresponding to the locations where mask_func(np.ones((n, n)), k) is True.      See also
triu, tril, triu_indices, tril_indices

  Notes  New in version 1.4.0.  Examples These are the indices that would allow you to access the upper triangular part of any 3x3 array: >>> iu = np.mask_indices(3, np.triu)
 For example, if a is a 3x3 array: >>> a = np.arange(9).reshape(3, 3)
>>> a
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])
>>> a[iu]
array([0, 1, 2, 4, 5, 8])
 An offset can be passed also to the masking function. This gets us the indices starting on the first diagonal right of the main one: >>> iu1 = np.mask_indices(3, np.triu, 1)
 with which we now extract only three elements: >>> a[iu1]
array([1, 2, 5])


numpy.mat   numpy.mat(data, dtype=None)[source]

Interpret the input as a matrix. Unlike matrix, asmatrix does not make a copy if the input is already a matrix or an ndarray. Equivalent to matrix(data, copy=False).  Parameters

dataarray_like

Input data.
dtypedata-type

Data-type of the output matrix.    Returns

matmatrix

data interpreted as a matrix.     Examples >>> x = np.array([[1, 2], [3, 4]])
 >>> m = np.asmatrix(x)
 >>> x[0,0] = 5
 >>> m
matrix([[5, 2],
        [3, 4]])


numpy.matmul   numpy.matmul(x1, x2, /, out=None, *, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj, axes, axis]) = <ufunc 'matmul'>

Matrix product of two arrays.  Parameters

x1, x2array_like

Input arrays, scalars not allowed.
outndarray, optional

A location into which the result is stored. If provided, it must have a shape that matches the signature (n,k),(k,m)->(n,m). If not provided or None, a freshly-allocated array is returned.  **kwargs

For other keyword-only arguments, see the ufunc docs.  New in version 1.16: Now handles ufunc kwargs     Returns

yndarray

The matrix product of the inputs. This is a scalar only when both x1, x2 are 1-d vectors.    Raises
 ValueError

If the last dimension of x1 is not the same size as the second-to-last dimension of x2. If a scalar value is passed in.      See also  vdot

Complex-conjugating dot product.  tensordot

Sum products over arbitrary axes.  einsum

Einstein summation convention.  dot

alternative matrix product with different broadcasting rules.    Notes The behavior depends on the arguments in the following way.  If both arguments are 2-D they are multiplied like conventional matrices. If either argument is N-D, N > 2, it is treated as a stack of matrices residing in the last two indexes and broadcast accordingly. If the first argument is 1-D, it is promoted to a matrix by prepending a 1 to its dimensions. After matrix multiplication the prepended 1 is removed. If the second argument is 1-D, it is promoted to a matrix by appending a 1 to its dimensions. After matrix multiplication the appended 1 is removed.  matmul differs from dot in two important ways:  Multiplication by scalars is not allowed, use * instead.
Stacks of matrices are broadcast together as if the matrices were elements, respecting the signature (n,k),(k,m)->(n,m): >>> a = np.ones([9, 5, 7, 4])
>>> c = np.ones([9, 5, 4, 3])
>>> np.dot(a, c).shape
(9, 5, 7, 9, 5, 3)
>>> np.matmul(a, c).shape
(9, 5, 7, 3)
>>> # n is 7, k is 4, m is 3
   The matmul function implements the semantics of the @ operator introduced in Python 3.5 following PEP 465. Examples For 2-D arrays it is the matrix product: >>> a = np.array([[1, 0],
...               [0, 1]])
>>> b = np.array([[4, 1],
...               [2, 2]])
>>> np.matmul(a, b)
array([[4, 1],
       [2, 2]])
 For 2-D mixed with 1-D, the result is the usual. >>> a = np.array([[1, 0],
...               [0, 1]])
>>> b = np.array([1, 2])
>>> np.matmul(a, b)
array([1, 2])
>>> np.matmul(b, a)
array([1, 2])
 Broadcasting is conventional for stacks of arrays >>> a = np.arange(2 * 2 * 4).reshape((2, 2, 4))
>>> b = np.arange(2 * 2 * 4).reshape((2, 4, 2))
>>> np.matmul(a,b).shape
(2, 2, 2)
>>> np.matmul(a, b)[0, 1, 1]
98
>>> sum(a[0, 1, :] * b[0 , :, 1])
98
 Vector, vector returns the scalar inner product, but neither argument is complex-conjugated: >>> np.matmul([2j, 3j], [2j, 3j])
(-13+0j)
 Scalar multiplication raises an error. >>> np.matmul([1,2], 3)
Traceback (most recent call last):
...
ValueError: matmul: Input operand 1 does not have enough dimensions ...
 The @ operator can be used as a shorthand for np.matmul on ndarrays. >>> x1 = np.array([2j, 3j])
>>> x2 = np.array([2j, 3j])
>>> x1 @ x2
(-13+0j)
  New in version 1.10.0.


numpy.matrix   class numpy.matrix(data, dtype=None, copy=True)[source]

 Note It is no longer recommended to use this class, even for linear algebra. Instead use regular arrays. The class may be removed in the future.  Returns a matrix from an array-like object, or from a string of data. A matrix is a specialized 2-D array that retains its 2-D nature through operations. It has certain special operators, such as * (matrix multiplication) and ** (matrix power).  Parameters

dataarray_like or string

If data is a string, it is interpreted as a matrix with commas or spaces separating columns, and semicolons separating rows.
dtypedata-type

Data-type of the output matrix.
copybool

If data is already an ndarray, then this flag determines whether the data is copied (the default), or whether a view is constructed.      See also  array
  Examples >>> a = np.matrix('1 2; 3 4')
>>> a
matrix([[1, 2],
        [3, 4]])
 >>> np.matrix([[1, 2], [3, 4]])
matrix([[1, 2],
        [3, 4]])
  Attributes
 A

Return self as an ndarray object.  A1

Return self as a flattened ndarray.  H

Returns the (complex) conjugate transpose of self.  I

Returns the (multiplicative) inverse of invertible self.  T

Returns the transpose of the matrix.  base

Base object if memory is from some other object.  ctypes

An object to simplify the interaction of the array with the ctypes module.  data

Python buffer object pointing to the start of the array’s data.  dtype

Data-type of the array’s elements.  flags

Information about the memory layout of the array.  flat

A 1-D iterator over the array.  imag

The imaginary part of the array.  itemsize

Length of one array element in bytes.  nbytes

Total bytes consumed by the elements of the array.  ndim

Number of array dimensions.  real

The real part of the array.  shape

Tuple of array dimensions.  size

Number of elements in the array.  strides

Tuple of bytes to step in each dimension when traversing an array.     Methods
all([axis, out]) Test whether all matrix elements along a given axis evaluate to True.
any([axis, out]) Test whether any array element along a given axis evaluates to True.
argmax([axis, out]) Indexes of the maximum values along an axis.
argmin([axis, out]) Indexes of the minimum values along an axis.
argpartition(kth[, axis, kind, order]) Returns the indices that would partition this array.
argsort([axis, kind, order]) Returns the indices that would sort this array.
astype(dtype[, order, casting, subok, copy]) Copy of the array, cast to a specified type.
byteswap([inplace]) Swap the bytes of the array elements
choose(choices[, out, mode]) Use an index array to construct a new array from a set of choices.
clip([min, max, out]) Return an array whose values are limited to [min, max].
compress(condition[, axis, out]) Return selected slices of this array along given axis.
conj() Complex-conjugate all elements.
conjugate() Return the complex conjugate, element-wise.
copy([order]) Return a copy of the array.
cumprod([axis, dtype, out]) Return the cumulative product of the elements along the given axis.
cumsum([axis, dtype, out]) Return the cumulative sum of the elements along the given axis.
diagonal([offset, axis1, axis2]) Return specified diagonals.
dump(file) Dump a pickle of the array to the specified file.
dumps() Returns the pickle of the array as a string.
fill(value) Fill the array with a scalar value.
flatten([order]) Return a flattened copy of the matrix.
getA() Return self as an ndarray object.
getA1() Return self as a flattened ndarray.
getH() Returns the (complex) conjugate transpose of self.
getI() Returns the (multiplicative) inverse of invertible self.
getT() Returns the transpose of the matrix.
getfield(dtype[, offset]) Returns a field of the given array as a certain type.
item(*args) Copy an element of an array to a standard Python scalar and return it.
itemset(*args) Insert scalar into an array (scalar is cast to array's dtype, if possible)
max([axis, out]) Return the maximum value along an axis.
mean([axis, dtype, out]) Returns the average of the matrix elements along the given axis.
min([axis, out]) Return the minimum value along an axis.
newbyteorder([new_order]) Return the array with the same data viewed with a different byte order.
nonzero() Return the indices of the elements that are non-zero.
partition(kth[, axis, kind, order]) Rearranges the elements in the array in such a way that the value of the element in kth position is in the position it would be in a sorted array.
prod([axis, dtype, out]) Return the product of the array elements over the given axis.
ptp([axis, out]) Peak-to-peak (maximum - minimum) value along the given axis.
put(indices, values[, mode]) Set a.flat[n] = values[n] for all n in indices.
ravel([order]) Return a flattened matrix.
repeat(repeats[, axis]) Repeat elements of an array.
reshape(shape[, order]) Returns an array containing the same data with a new shape.
resize(new_shape[, refcheck]) Change shape and size of array in-place.
round([decimals, out]) Return a with each element rounded to the given number of decimals.
searchsorted(v[, side, sorter]) Find indices where elements of v should be inserted in a to maintain order.
setfield(val, dtype[, offset]) Put a value into a specified place in a field defined by a data-type.
setflags([write, align, uic]) Set array flags WRITEABLE, ALIGNED, (WRITEBACKIFCOPY and UPDATEIFCOPY), respectively.
sort([axis, kind, order]) Sort an array in-place.
squeeze([axis]) Return a possibly reshaped matrix.
std([axis, dtype, out, ddof]) Return the standard deviation of the array elements along the given axis.
sum([axis, dtype, out]) Returns the sum of the matrix elements, along the given axis.
swapaxes(axis1, axis2) Return a view of the array with axis1 and axis2 interchanged.
take(indices[, axis, out, mode]) Return an array formed from the elements of a at the given indices.
tobytes([order]) Construct Python bytes containing the raw data bytes in the array.
tofile(fid[, sep, format]) Write array to a file as text or binary (default).
tolist() Return the matrix as a (possibly nested) list.
tostring([order]) A compatibility alias for tobytes, with exactly the same behavior.
trace([offset, axis1, axis2, dtype, out]) Return the sum along diagonals of the array.
transpose(*axes) Returns a view of the array with axes transposed.
var([axis, dtype, out, ddof]) Returns the variance of the matrix elements, along the given axis.
view([dtype][, type]) New view of array with the same data.
dot


numpy.maximum   numpy.maximum(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'maximum'>

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 that element is returned. If both elements are NaNs then the first is returned. The latter distinction is important for complex NaNs, which are defined as at least one of the real or imaginary parts being a NaN. The net effect is that NaNs are propagated.  Parameters

x1, x2array_like

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).
outndarray, None, or tuple of ndarray and None, optional

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.
wherearray_like, optional

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.  **kwargs

For other keyword-only arguments, see the ufunc docs.    Returns

yndarray or scalar

The maximum of x1 and x2, element-wise. This is a scalar if both x1 and x2 are scalars.      See also  minimum

Element-wise minimum of two arrays, propagates NaNs.  fmax

Element-wise maximum of two arrays, ignores NaNs.  amax

The maximum value of an array along a given axis, propagates NaNs.  nanmax

The maximum value of an array along a given axis, ignores NaNs.
fmin, amin, nanmin

  Notes The maximum is equivalent to np.where(x1 >= x2, x1, x2) when neither x1 nor x2 are nans, but it is faster and does proper broadcasting. Examples >>> np.maximum([2, 3, 4], [1, 5, 2])
array([2, 5, 4])
 >>> np.maximum(np.eye(2), [0.5, 2]) # broadcasting
array([[ 1. ,  2. ],
       [ 0.5,  2. ]])
 >>> np.maximum([np.nan, 0, np.nan], [0, np.nan, np.nan])
array([nan, nan, nan])
>>> np.maximum(np.Inf, 1)
inf


numpy.maximum_sctype   numpy.maximum_sctype(t)[source]

Return the scalar type of highest precision of the same kind as the input.  Parameters

tdtype or dtype specifier

The input data type. This can be a dtype object or an object that is convertible to a dtype.    Returns

outdtype

The highest precision data type of the same kind (dtype.kind) as t.      See also
obj2sctype, mintypecode, sctype2char

dtype
  Examples >>> np.maximum_sctype(int)
<class 'numpy.int64'>
>>> np.maximum_sctype(np.uint8)
<class 'numpy.uint64'>
>>> np.maximum_sctype(complex)
<class 'numpy.complex256'> # may vary
 >>> np.maximum_sctype(str)
<class 'numpy.str_'>
 >>> np.maximum_sctype('i2')
<class 'numpy.int64'>
>>> np.maximum_sctype('f4')
<class 'numpy.float128'> # may vary


numpy.may_share_memory   numpy.may_share_memory(a, b, /, max_work=None)

Determine if two arrays might share memory A return of True does not necessarily mean that the two arrays share any element. It just means that they might. Only the memory bounds of a and b are checked by default.  Parameters

a, bndarray

Input arrays
max_workint, optional

Effort to spend on solving the overlap problem. See shares_memory for details. Default for may_share_memory is to do a bounds check.    Returns

outbool

    See also  shares_memory
  Examples >>> np.may_share_memory(np.array([1,2]), np.array([5,8,9]))
False
>>> x = np.zeros([3, 4])
>>> np.may_share_memory(x[:,0], x[:,1])
True


numpy.mean   numpy.mean(a, axis=None, dtype=None, out=None, keepdims=<no value>, *, where=<no value>)[source]

Compute the arithmetic mean along the specified axis. Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. float64 intermediate and return values are used for integer inputs.  Parameters

aarray_like

Array containing numbers whose mean is desired. If a is not an array, a conversion is attempted.
axisNone or int or tuple of ints, optional

Axis or axes along which the means are computed. The default is to compute the mean of the flattened array.  New in version 1.7.0.  If this is a tuple of ints, a mean is performed over multiple axes, instead of a single axis or all the axes as before.
dtypedata-type, optional

Type to use in computing the mean. For integer inputs, the default is float64; for floating point inputs, it is the same as the input dtype.
outndarray, optional

Alternate output array in which to place the result. The default is None; if provided, it must have the same shape as the expected output, but the type will be cast if necessary. See Output type determination for more details.
keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. If the default value is passed, then keepdims will not be passed through to the mean method of sub-classes of ndarray, however any non-default value will be. If the sub-class’ method does not implement keepdims any exceptions will be raised.
wherearray_like of bool, optional

Elements to include in the mean. See reduce for details.  New in version 1.20.0.     Returns

mndarray, see dtype parameter above

If out=None, returns a new array containing the mean values, otherwise a reference to the output array is returned.      See also  average

Weighted average
std, var, nanmean, nanstd, nanvar

  Notes The arithmetic mean is the sum of the elements along the axis divided by the number of elements. Note that for floating-point input, the mean is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32 (see example below). Specifying a higher-precision accumulator using the dtype keyword can alleviate this issue. By default, float16 results are computed using float32 intermediates for extra precision. Examples >>> a = np.array([[1, 2], [3, 4]])
>>> np.mean(a)
2.5
>>> np.mean(a, axis=0)
array([2., 3.])
>>> np.mean(a, axis=1)
array([1.5, 3.5])
 In single precision, mean can be inaccurate: >>> a = np.zeros((2, 512*512), dtype=np.float32)
>>> a[0, :] = 1.0
>>> a[1, :] = 0.1
>>> np.mean(a)
0.54999924
 Computing the mean in float64 is more accurate: >>> np.mean(a, dtype=np.float64)
0.55000000074505806 # may vary
 Specifying a where argument: >>> a = np.array([[5, 9, 13], [14, 10, 12], [11, 15, 19]]) >>> np.mean(a) 12.0 >>> np.mean(a, where=[[True], [False], [False]]) 9.0


numpy.median   numpy.median(a, axis=None, out=None, overwrite_input=False, keepdims=False)[source]

Compute the median along the specified axis. Returns the median of the array elements.  Parameters

aarray_like

Input array or object that can be converted to an array.
axis{int, sequence of int, None}, optional

Axis or axes along which the medians are computed. The default is to compute the median along a flattened version of the array. A sequence of axes is supported since version 1.9.0.
outndarray, optional

Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output, but the type (of the output) will be cast if necessary.
overwrite_inputbool, optional

If True, then allow use of memory of input array a for calculations. The input array will be modified by the call to median. This will save memory when you do not need to preserve the contents of the input array. Treat the input as undefined, but it will probably be fully or partially sorted. Default is False. If overwrite_input is True and a is not already an ndarray, an error will be raised.
keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original arr.  New in version 1.9.0.     Returns

medianndarray

A new array holding the result. If the input contains integers or floats smaller than float64, then the output data-type is np.float64. Otherwise, the data-type of the output is the same as that of the input. If out is specified, that array is returned instead.      See also
mean, percentile

  Notes Given a vector V of length N, the median of V is the middle value of a sorted copy of V, V_sorted - i e., V_sorted[(N-1)/2], when N is odd, and the average of the two middle values of V_sorted when N is even. Examples >>> a = np.array([[10, 7, 4], [3, 2, 1]])
>>> a
array([[10,  7,  4],
       [ 3,  2,  1]])
>>> np.median(a)
3.5
>>> np.median(a, axis=0)
array([6.5, 4.5, 2.5])
>>> np.median(a, axis=1)
array([7.,  2.])
>>> m = np.median(a, axis=0)
>>> out = np.zeros_like(m)
>>> np.median(a, axis=0, out=m)
array([6.5,  4.5,  2.5])
>>> m
array([6.5,  4.5,  2.5])
>>> b = a.copy()
>>> np.median(b, axis=1, overwrite_input=True)
array([7.,  2.])
>>> assert not np.all(a==b)
>>> b = a.copy()
>>> np.median(b, axis=None, overwrite_input=True)
3.5
>>> assert not np.all(a==b)


numpy.memmap   class numpy.memmap(filename, dtype=<class 'numpy.ubyte'>, mode='r+', offset=0, shape=None, order='C')[source]

Create a memory-map to an array stored in a binary file on disk. Memory-mapped files are used for accessing small segments of large files on disk, without reading the entire file into memory. NumPy’s memmap’s are array-like objects. This differs from Python’s mmap module, which uses file-like objects. This subclass of ndarray has some unpleasant interactions with some operations, because it doesn’t quite fit properly as a subclass. An alternative to using this subclass is to create the mmap object yourself, then create an ndarray with ndarray.__new__ directly, passing the object created in its ‘buffer=’ parameter. This class may at some point be turned into a factory function which returns a view into an mmap buffer. Flush the memmap instance to write the changes to the file. Currently there is no API to close the underlying mmap. It is tricky to ensure the resource is actually closed, since it may be shared between different memmap instances.  Parameters

filenamestr, file-like object, or pathlib.Path instance

The file name or file object to be used as the array data buffer.
dtypedata-type, optional

The data-type used to interpret the file contents. Default is uint8.
mode{‘r+’, ‘r’, ‘w+’, ‘c’}, optional

The file is opened in this mode:
‘r’ Open existing file for reading only.
‘r+’ Open existing file for reading and writing.
‘w+’ Create or overwrite existing file for reading and writing.
‘c’ Copy-on-write: assignments affect data in memory, but changes are not saved to disk. The file on disk is read-only.   Default is ‘r+’.
offsetint, optional

In the file, array data starts at this offset. Since offset is measured in bytes, it should normally be a multiple of the byte-size of dtype. When mode != 'r', even positive offsets beyond end of file are valid; The file will be extended to accommodate the additional data. By default, memmap will start at the beginning of the file, even if filename is a file pointer fp and fp.tell() != 0.
shapetuple, optional

The desired shape of the array. If mode == 'r' and the number of remaining bytes after offset is not a multiple of the byte-size of dtype, you must specify shape. By default, the returned array will be 1-D with the number of elements determined by file size and data-type.
order{‘C’, ‘F’}, optional

Specify the order of the ndarray memory layout: row-major, C-style or column-major, Fortran-style. This only has an effect if the shape is greater than 1-D. The default order is ‘C’.      See also  lib.format.open_memmap

Create or load a memory-mapped .npy file.    Notes The memmap object can be used anywhere an ndarray is accepted. Given a memmap fp, isinstance(fp, numpy.ndarray) returns True. Memory-mapped files cannot be larger than 2GB on 32-bit systems. When a memmap causes a file to be created or extended beyond its current size in the filesystem, the contents of the new part are unspecified. On systems with POSIX filesystem semantics, the extended part will be filled with zero bytes. Examples >>> data = np.arange(12, dtype='float32')
>>> data.resize((3,4))
 This example uses a temporary file so that doctest doesn’t write files to your directory. You would use a ‘normal’ filename. >>> from tempfile import mkdtemp
>>> import os.path as path
>>> filename = path.join(mkdtemp(), 'newfile.dat')
 Create a memmap with dtype and shape that matches our data: >>> fp = np.memmap(filename, dtype='float32', mode='w+', shape=(3,4))
>>> fp
memmap([[0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.]], dtype=float32)
 Write data to memmap array: >>> fp[:] = data[:]
>>> fp
memmap([[  0.,   1.,   2.,   3.],
        [  4.,   5.,   6.,   7.],
        [  8.,   9.,  10.,  11.]], dtype=float32)
 >>> fp.filename == path.abspath(filename)
True
 Flushes memory changes to disk in order to read them back >>> fp.flush()
 Load the memmap and verify data was stored: >>> newfp = np.memmap(filename, dtype='float32', mode='r', shape=(3,4))
>>> newfp
memmap([[  0.,   1.,   2.,   3.],
        [  4.,   5.,   6.,   7.],
        [  8.,   9.,  10.,  11.]], dtype=float32)
 Read-only memmap: >>> fpr = np.memmap(filename, dtype='float32', mode='r', shape=(3,4))
>>> fpr.flags.writeable
False
 Copy-on-write memmap: >>> fpc = np.memmap(filename, dtype='float32', mode='c', shape=(3,4))
>>> fpc.flags.writeable
True
 It’s possible to assign to copy-on-write array, but values are only written into the memory copy of the array, and not written to disk: >>> fpc
memmap([[  0.,   1.,   2.,   3.],
        [  4.,   5.,   6.,   7.],
        [  8.,   9.,  10.,  11.]], dtype=float32)
>>> fpc[0,:] = 0
>>> fpc
memmap([[  0.,   0.,   0.,   0.],
        [  4.,   5.,   6.,   7.],
        [  8.,   9.,  10.,  11.]], dtype=float32)
 File on disk is unchanged: >>> fpr
memmap([[  0.,   1.,   2.,   3.],
        [  4.,   5.,   6.,   7.],
        [  8.,   9.,  10.,  11.]], dtype=float32)
 Offset into a memmap: >>> fpo = np.memmap(filename, dtype='float32', mode='r', offset=16)
>>> fpo
memmap([  4.,   5.,   6.,   7.,   8.,   9.,  10.,  11.], dtype=float32)
  Attributes

filenamestr or pathlib.Path instance

Path to the mapped file.
offsetint

Offset position in the file.
modestr

File mode.     Methods
flush() Write any changes in the array to the file on disk.


numpy.meshgrid   numpy.meshgrid(*xi, copy=True, sparse=False, indexing='xy')[source]

Return coordinate matrices from coordinate vectors. Make N-D coordinate arrays for vectorized evaluations of N-D scalar/vector fields over N-D grids, given one-dimensional coordinate arrays x1, x2,…, xn.  Changed in version 1.9: 1-D and 0-D cases are allowed.   Parameters

x1, x2,…, xnarray_like

1-D arrays representing the coordinates of a grid.
indexing{‘xy’, ‘ij’}, optional

Cartesian (‘xy’, default) or matrix (‘ij’) indexing of output. See Notes for more details.  New in version 1.7.0.
sparsebool, optional

If True the shape of the returned coordinate array for dimension i is reduced from (N1, ..., Ni, ... Nn) to (1, ..., 1, Ni, 1, ..., 1). These sparse coordinate grids are intended to be use with Broadcasting. When all coordinates are used in an expression, broadcasting still leads to a fully-dimensonal result array. Default is False.  New in version 1.7.0.
copybool, optional

If False, a view into the original arrays are returned in order to conserve memory. Default is True. Please note that sparse=False, copy=False will likely return non-contiguous arrays. Furthermore, more than one element of a broadcast array may refer to a single memory location. If you need to write to the arrays, make copies first.  New in version 1.7.0.     Returns

X1, X2,…, XNndarray

For vectors x1, x2,…, ‘xn’ with lengths Ni=len(xi) , return (N1, N2, N3,...Nn) shaped arrays if indexing=’ij’ or (N2, N1, N3,...Nn) shaped arrays if indexing=’xy’ with the elements of xi repeated to fill the matrix along the first dimension for x1, the second for x2 and so on.      See also  mgrid

Construct a multi-dimensional “meshgrid” using indexing notation.  ogrid

Construct an open multi-dimensional “meshgrid” using indexing notation.    Notes This function supports both indexing conventions through the indexing keyword argument. Giving the string ‘ij’ returns a meshgrid with matrix indexing, while ‘xy’ returns a meshgrid with Cartesian indexing. In the 2-D case with inputs of length M and N, the outputs are of shape (N, M) for ‘xy’ indexing and (M, N) for ‘ij’ indexing. In the 3-D case with inputs of length M, N and P, outputs are of shape (N, M, P) for ‘xy’ indexing and (M, N, P) for ‘ij’ indexing. The difference is illustrated by the following code snippet: xv, yv = np.meshgrid(x, y, indexing='ij')
for i in range(nx):
    for j in range(ny):
        # treat xv[i,j], yv[i,j]

xv, yv = np.meshgrid(x, y, indexing='xy')
for i in range(nx):
    for j in range(ny):
        # treat xv[j,i], yv[j,i]
 In the 1-D and 0-D case, the indexing and sparse keywords have no effect. Examples >>> nx, ny = (3, 2)
>>> x = np.linspace(0, 1, nx)
>>> y = np.linspace(0, 1, ny)
>>> xv, yv = np.meshgrid(x, y)
>>> xv
array([[0. , 0.5, 1. ],
       [0. , 0.5, 1. ]])
>>> yv
array([[0.,  0.,  0.],
       [1.,  1.,  1.]])
>>> xv, yv = np.meshgrid(x, y, sparse=True)  # make sparse output arrays
>>> xv
array([[0. ,  0.5,  1. ]])
>>> yv
array([[0.],
       [1.]])
 meshgrid is very useful to evaluate functions on a grid. If the function depends on all coordinates, you can use the parameter sparse=True to save memory and computation time. >>> x = np.linspace(-5, 5, 101)
>>> y = np.linspace(-5, 5, 101)
>>> # full coorindate arrays
>>> xx, yy = np.meshgrid(x, y)
>>> zz = np.sqrt(xx**2 + yy**2)
>>> xx.shape, yy.shape, zz.shape
((101, 101), (101, 101), (101, 101))
>>> # sparse coordinate arrays
>>> xs, ys = np.meshgrid(x, y, sparse=True)
>>> zs = np.sqrt(xs**2 + ys**2)
>>> xs.shape, ys.shape, zs.shape
((1, 101), (101, 1), (101, 101))
>>> np.array_equal(zz, zs)
True
 >>> import matplotlib.pyplot as plt
>>> h = plt.contourf(x, y, zs)
>>> plt.axis('scaled')
>>> plt.colorbar()
>>> plt.show()


numpy.mgrid   numpy.mgrid = <numpy.lib.index_tricks.MGridClass object>

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

class of ogrid and mgrid objects  ogrid

like mgrid but returns open (not fleshed out) mesh grids  r_

array concatenator    Examples >>> np.mgrid[0:5,0:5]
array([[[0, 0, 0, 0, 0],
        [1, 1, 1, 1, 1],
        [2, 2, 2, 2, 2],
        [3, 3, 3, 3, 3],
        [4, 4, 4, 4, 4]],
       [[0, 1, 2, 3, 4],
        [0, 1, 2, 3, 4],
        [0, 1, 2, 3, 4],
        [0, 1, 2, 3, 4],
        [0, 1, 2, 3, 4]]])
>>> np.mgrid[-1:1:5j]
array([-1. , -0.5,  0. ,  0.5,  1. ])


numpy.min_scalar_type   numpy.min_scalar_type(a, /)

For scalar a, returns the data type with the smallest size and smallest scalar kind which can hold its value. For non-scalar array a, returns the vector’s dtype unmodified. Floating point values are not demoted to integers, and complex values are not demoted to floats.  Parameters

ascalar or array_like

The value whose minimal data type is to be found.    Returns

outdtype

The minimal data type.      See also
result_type, promote_types, dtype, can_cast

  Notes  New in version 1.6.0.  Examples >>> np.min_scalar_type(10)
dtype('uint8')
 >>> np.min_scalar_type(-260)
dtype('int16')
 >>> np.min_scalar_type(3.1)
dtype('float16')
 >>> np.min_scalar_type(1e50)
dtype('float64')
 >>> np.min_scalar_type(np.arange(4,dtype='f8'))
dtype('float64')


numpy.minimum   numpy.minimum(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'minimum'>

Element-wise minimum of array elements. Compare two arrays and returns a new array containing the element-wise minima. If one of the elements being compared is a NaN, then that element is returned. If both elements are NaNs then the first is returned. The latter distinction is important for complex NaNs, which are defined as at least one of the real or imaginary parts being a NaN. The net effect is that NaNs are propagated.  Parameters

x1, x2array_like

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).
outndarray, None, or tuple of ndarray and None, optional

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.
wherearray_like, optional

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.  **kwargs

For other keyword-only arguments, see the ufunc docs.    Returns

yndarray or scalar

The minimum of x1 and x2, element-wise. This is a scalar if both x1 and x2 are scalars.      See also  maximum

Element-wise maximum of two arrays, propagates NaNs.  fmin

Element-wise minimum of two arrays, ignores NaNs.  amin

The minimum value of an array along a given axis, propagates NaNs.  nanmin

The minimum value of an array along a given axis, ignores NaNs.
fmax, amax, nanmax

  Notes The minimum is equivalent to np.where(x1 <= x2, x1, x2) when neither x1 nor x2 are NaNs, but it is faster and does proper broadcasting. Examples >>> np.minimum([2, 3, 4], [1, 5, 2])
array([1, 3, 2])
 >>> np.minimum(np.eye(2), [0.5, 2]) # broadcasting
array([[ 0.5,  0. ],
       [ 0. ,  1. ]])
 >>> np.minimum([np.nan, 0, np.nan],[0, np.nan, np.nan])
array([nan, nan, nan])
>>> np.minimum(-np.Inf, 1)
-inf


numpy.mintypecode   numpy.mintypecode(typechars, typeset='GDFgdf', default='d')[source]

Return the character for the minimum-size type to which given types can be safely cast. The returned type character must represent the smallest size dtype such that an array of the returned type can handle the data from an array of all types in typechars (or if typechars is an array, then its dtype.char).  Parameters

typecharslist of str or array_like

If a list of strings, each string should represent a dtype. If array_like, the character representation of the array dtype is used.
typesetstr or list of str, optional

The set of characters that the returned character is chosen from. The default set is ‘GDFgdf’.
defaultstr, optional

The default character, this is returned if none of the characters in typechars matches a character in typeset.    Returns

typecharstr

The character representing the minimum-size type that was found.      See also
dtype, sctype2char, maximum_sctype

  Examples >>> np.mintypecode(['d', 'f', 'S'])
'd'
>>> x = np.array([1.1, 2-3.j])
>>> np.mintypecode(x)
'D'
 >>> np.mintypecode('abceh', default='G')
'G'


numpy.mod   numpy.mod(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'remainder'>

Returns the element-wise remainder of division. Computes the remainder complementary to the floor_divide function. It is equivalent to the Python modulus operator``x1 % x2`` and has the same sign as the divisor x2. The MATLAB function equivalent to np.remainder is mod.  Warning This should not be confused with:  Python 3.7’s math.remainder and C’s remainder, which computes the IEEE remainder, which are the complement to round(x1 / x2). The MATLAB rem function and or the C % operator which is the complement to int(x1 / x2).    Parameters

x1array_like

Dividend array.
x2array_like

Divisor array. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).
outndarray, None, or tuple of ndarray and None, optional

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.
wherearray_like, optional

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.  **kwargs

For other keyword-only arguments, see the ufunc docs.    Returns

yndarray

The element-wise remainder of the quotient floor_divide(x1, x2). This is a scalar if both x1 and x2 are scalars.      See also  floor_divide

Equivalent of Python // operator.  divmod

Simultaneous floor division and remainder.  fmod

Equivalent of the MATLAB rem function.
divide, floor

  Notes Returns 0 when x2 is 0 and both x1 and x2 are (arrays of) integers. mod is an alias of remainder. Examples >>> np.remainder([4, 7], [2, 3])
array([0, 1])
>>> np.remainder(np.arange(7), 5)
array([0, 1, 2, 3, 4, 0, 1])
 The % operator can be used as a shorthand for np.remainder on ndarrays. >>> x1 = np.arange(7)
>>> x1 % 5
array([0, 1, 2, 3, 4, 0, 1])


numpy.modf   numpy.modf(x, [out1, out2, ]/, [out=(None, None), ]*, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'modf'>

Return the fractional and integral parts of an array, element-wise. The fractional and integral parts are negative if the given number is negative.  Parameters

xarray_like

Input array.
outndarray, None, or tuple of ndarray and None, optional

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.
wherearray_like, optional

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.  **kwargs

For other keyword-only arguments, see the ufunc docs.    Returns

y1ndarray

Fractional part of x. This is a scalar if x is a scalar.
y2ndarray

Integral part of x. This is a scalar if x is a scalar.      See also  divmod

divmod(x, 1) is equivalent to modf with the return values switched, except it always has a positive remainder.    Notes For integer input the return values are floats. Examples >>> np.modf([0, 3.5])
(array([ 0. ,  0.5]), array([ 0.,  3.]))
>>> np.modf(-0.5)
(-0.5, -0)


numpy.moveaxis   numpy.moveaxis(a, source, destination)[source]

Move axes of an array to new positions. Other axes remain in their original order.  New in version 1.11.0.   Parameters

anp.ndarray

The array whose axes should be reordered.
sourceint or sequence of int

Original positions of the axes to move. These must be unique.
destinationint or sequence of int

Destination positions for each of the original axes. These must also be unique.    Returns

resultnp.ndarray

Array with moved axes. This array is a view of the input array.      See also  transpose

Permute the dimensions of an array.  swapaxes

Interchange two axes of an array.    Examples >>> x = np.zeros((3, 4, 5))
>>> np.moveaxis(x, 0, -1).shape
(4, 5, 3)
>>> np.moveaxis(x, -1, 0).shape
(5, 3, 4)
 These all achieve the same result: >>> np.transpose(x).shape
(5, 4, 3)
>>> np.swapaxes(x, 0, -1).shape
(5, 4, 3)
>>> np.moveaxis(x, [0, 1], [-1, -2]).shape
(5, 4, 3)
>>> np.moveaxis(x, [0, 1, 2], [-1, -2, -3]).shape
(5, 4, 3)


numpy.msort   numpy.msort(a)[source]

Return a copy of an array sorted along the first axis.  Parameters

aarray_like

Array to be sorted.    Returns

sorted_arrayndarray

Array of the same type and shape as a.      See also  sort
  Notes np.msort(a) is equivalent to np.sort(a, axis=0).


numpy.multiply   numpy.multiply(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'multiply'>

Multiply arguments element-wise.  Parameters

x1, x2array_like

Input arrays to be multiplied. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).
outndarray, None, or tuple of ndarray and None, optional

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.
wherearray_like, optional

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.  **kwargs

For other keyword-only arguments, see the ufunc docs.    Returns

yndarray

The product of x1 and x2, element-wise. This is a scalar if both x1 and x2 are scalars.     Notes Equivalent to x1 * x2 in terms of array broadcasting. Examples >>> np.multiply(2.0, 4.0)
8.0
 >>> x1 = np.arange(9.0).reshape((3, 3))
>>> x2 = np.arange(3.0)
>>> np.multiply(x1, x2)
array([[  0.,   1.,   4.],
       [  0.,   4.,  10.],
       [  0.,   7.,  16.]])
 The * operator can be used as a shorthand for np.multiply on ndarrays. >>> x1 = np.arange(9.0).reshape((3, 3))
>>> x2 = np.arange(3.0)
>>> x1 * x2
array([[  0.,   1.,   4.],
       [  0.,   4.,  10.],
       [  0.,   7.,  16.]])


numpy.NAN

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


numpy.NaN

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


numpy.nan

IEEE 754 floating point representation of Not a Number (NaN). Returns y : A floating point representation of Not a Number. See Also 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) Notes 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. Examples >>> np.nan
nan
>>> np.log(-1)
nan
>>> np.log([-1, 1, 2])
array([        NaN,  0.        ,  0.69314718])


numpy.nan_to_num   numpy.nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None)[source]

Replace NaN with zero and infinity with large finite numbers (default behaviour) or with the numbers defined by the user using the nan, posinf and/or neginf keywords. If x is inexact, NaN is replaced by zero or by the user defined value in nan keyword, infinity is replaced by the largest finite floating point values representable by x.dtype or by the user defined value in posinf keyword and -infinity is replaced by the most negative finite floating point values representable by x.dtype or by the user defined value in neginf keyword. For complex dtypes, the above is applied to each of the real and imaginary components of x separately. If x is not inexact, then no replacements are made.  Parameters

xscalar or array_like

Input data.
copybool, optional

Whether to create a copy of x (True) or to replace values in-place (False). The in-place operation only occurs if casting to an array does not require a copy. Default is True.  New in version 1.13.
nanint, float, optional

Value to be used to fill NaN values. If no value is passed then NaN values will be replaced with 0.0.  New in version 1.17.
posinfint, float, optional

Value to be used to fill positive infinity values. If no value is passed then positive infinity values will be replaced with a very large number.  New in version 1.17.
neginfint, float, optional

Value to be used to fill negative infinity values. If no value is passed then negative infinity values will be replaced with a very small (or negative) number.  New in version 1.17.     Returns

outndarray

x, with the non-finite values replaced. If copy is False, this may be x itself.      See also  isinf

Shows which elements are positive or negative infinity.  isneginf

Shows which elements are negative infinity.  isposinf

Shows which elements are positive infinity.  isnan

Shows which elements are Not a Number (NaN).  isfinite

Shows which elements are finite (not NaN, not infinity)    Notes NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity. Examples >>> np.nan_to_num(np.inf)
1.7976931348623157e+308
>>> np.nan_to_num(-np.inf)
-1.7976931348623157e+308
>>> np.nan_to_num(np.nan)
0.0
>>> x = np.array([np.inf, -np.inf, np.nan, -128, 128])
>>> np.nan_to_num(x)
array([ 1.79769313e+308, -1.79769313e+308,  0.00000000e+000, # may vary
       -1.28000000e+002,  1.28000000e+002])
>>> np.nan_to_num(x, nan=-9999, posinf=33333333, neginf=33333333)
array([ 3.3333333e+07,  3.3333333e+07, -9.9990000e+03,
       -1.2800000e+02,  1.2800000e+02])
>>> y = np.array([complex(np.inf, np.nan), np.nan, complex(np.nan, np.inf)])
array([  1.79769313e+308,  -1.79769313e+308,   0.00000000e+000, # may vary
     -1.28000000e+002,   1.28000000e+002])
>>> np.nan_to_num(y)
array([  1.79769313e+308 +0.00000000e+000j, # may vary
         0.00000000e+000 +0.00000000e+000j,
         0.00000000e+000 +1.79769313e+308j])
>>> np.nan_to_num(y, nan=111111, posinf=222222)
array([222222.+111111.j, 111111.     +0.j, 111111.+222222.j])


numpy.nanargmax   numpy.nanargmax(a, axis=None, out=None, *, keepdims=<no value>)[source]

Return the indices of the maximum values in the specified axis ignoring NaNs. For all-NaN slices ValueError is raised. Warning: the results cannot be trusted if a slice contains only NaNs and -Infs.  Parameters

aarray_like

Input data.
axisint, optional

Axis along which to operate. By default flattened input is used.
outarray, optional

If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype.  New in version 1.22.0.
keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the array.  New in version 1.22.0.     Returns

index_arrayndarray

An array of indices or a single index value.      See also
argmax, nanargmin

  Examples >>> a = np.array([[np.nan, 4], [2, 3]])
>>> np.argmax(a)
0
>>> np.nanargmax(a)
1
>>> np.nanargmax(a, axis=0)
array([1, 0])
>>> np.nanargmax(a, axis=1)
array([1, 1])


numpy.nanargmin   numpy.nanargmin(a, axis=None, out=None, *, keepdims=<no value>)[source]

Return the indices of the minimum values in the specified axis ignoring NaNs. For all-NaN slices ValueError is raised. Warning: the results cannot be trusted if a slice contains only NaNs and Infs.  Parameters

aarray_like

Input data.
axisint, optional

Axis along which to operate. By default flattened input is used.
outarray, optional

If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype.  New in version 1.22.0.
keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the array.  New in version 1.22.0.     Returns

index_arrayndarray

An array of indices or a single index value.      See also
argmin, nanargmax

  Examples >>> a = np.array([[np.nan, 4], [2, 3]])
>>> np.argmin(a)
0
>>> np.nanargmin(a)
2
>>> np.nanargmin(a, axis=0)
array([1, 1])
>>> np.nanargmin(a, axis=1)
array([1, 0])


numpy.nancumprod   numpy.nancumprod(a, axis=None, dtype=None, out=None)[source]

Return the cumulative product of array elements over a given axis treating Not a Numbers (NaNs) as one. The cumulative product does not change when NaNs are encountered and leading NaNs are replaced by ones. Ones are returned for slices that are all-NaN or empty.  New in version 1.12.0.   Parameters

aarray_like

Input array.
axisint, optional

Axis along which the cumulative product is computed. By default the input is flattened.
dtypedtype, optional

Type of the returned array, as well as of the accumulator in which the elements are multiplied. If dtype is not specified, it defaults to the dtype of a, unless a has an integer dtype with a precision less than that of the default platform integer. In that case, the default platform integer is used instead.
outndarray, optional

Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type of the resulting values will be cast if necessary.    Returns

nancumprodndarray

A new array holding the result is returned unless out is specified, in which case it is returned.      See also  numpy.cumprod

Cumulative product across array propagating NaNs.  isnan

Show which elements are NaN.    Examples >>> np.nancumprod(1)
array([1])
>>> np.nancumprod([1])
array([1])
>>> np.nancumprod([1, np.nan])
array([1.,  1.])
>>> a = np.array([[1, 2], [3, np.nan]])
>>> np.nancumprod(a)
array([1.,  2.,  6.,  6.])
>>> np.nancumprod(a, axis=0)
array([[1.,  2.],
       [3.,  2.]])
>>> np.nancumprod(a, axis=1)
array([[1.,  2.],
       [3.,  3.]])


numpy.nancumsum   numpy.nancumsum(a, axis=None, dtype=None, out=None)[source]

Return the cumulative sum of array elements over a given axis treating Not a Numbers (NaNs) as zero. The cumulative sum does not change when NaNs are encountered and leading NaNs are replaced by zeros. Zeros are returned for slices that are all-NaN or empty.  New in version 1.12.0.   Parameters

aarray_like

Input array.
axisint, optional

Axis along which the cumulative sum is computed. The default (None) is to compute the cumsum over the flattened array.
dtypedtype, optional

Type of the returned array and of the accumulator in which the elements are summed. If dtype is not specified, it defaults to the dtype of a, unless a has an integer dtype with a precision less than that of the default platform integer. In that case, the default platform integer is used.
outndarray, optional

Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. See Output type determination for more details.    Returns

nancumsumndarray.

A new array holding the result is returned unless out is specified, in which it is returned. The result has the same size as a, and the same shape as a if axis is not None or a is a 1-d array.      See also  numpy.cumsum

Cumulative sum across array propagating NaNs.  isnan

Show which elements are NaN.    Examples >>> np.nancumsum(1)
array([1])
>>> np.nancumsum([1])
array([1])
>>> np.nancumsum([1, np.nan])
array([1.,  1.])
>>> a = np.array([[1, 2], [3, np.nan]])
>>> np.nancumsum(a)
array([1.,  3.,  6.,  6.])
>>> np.nancumsum(a, axis=0)
array([[1.,  2.],
       [4.,  2.]])
>>> np.nancumsum(a, axis=1)
array([[1.,  3.],
       [3.,  3.]])


numpy.nanmax   numpy.nanmax(a, axis=None, out=None, keepdims=<no value>, initial=<no value>, where=<no value>)[source]

Return the maximum of an array or maximum along an axis, ignoring any NaNs. When all-NaN slices are encountered a RuntimeWarning is raised and NaN is returned for that slice.  Parameters

aarray_like

Array containing numbers whose maximum is desired. If a is not an array, a conversion is attempted.
axis{int, tuple of int, None}, optional

Axis or axes along which the maximum is computed. The default is to compute the maximum of the flattened array.
outndarray, optional

Alternate output array in which to place the result. The default is None; if provided, it must have the same shape as the expected output, but the type will be cast if necessary. See Output type determination for more details.  New in version 1.8.0.
keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a. If the value is anything but the default, then keepdims will be passed through to the max method of sub-classes of ndarray. If the sub-classes methods does not implement keepdims any exceptions will be raised.  New in version 1.8.0.
initialscalar, optional

The minimum value of an output element. Must be present to allow computation on empty slice. See reduce for details.  New in version 1.22.0.
wherearray_like of bool, optional

Elements to compare for the maximum. See reduce for details.  New in version 1.22.0.     Returns

nanmaxndarray

An array with the same shape as a, with the specified axis removed. If a is a 0-d array, or if axis is None, an ndarray scalar is returned. The same dtype as a is returned.      See also  nanmin

The minimum value of an array along a given axis, ignoring any NaNs.  amax

The maximum value of an array along a given axis, propagating any NaNs.  fmax

Element-wise maximum of two arrays, ignoring any NaNs.  maximum

Element-wise maximum of two arrays, propagating any NaNs.  isnan

Shows which elements are Not a Number (NaN).  isfinite

Shows which elements are neither NaN nor infinity.
amin, fmin, minimum

  Notes NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity. Positive infinity is treated as a very large number and negative infinity is treated as a very small (i.e. negative) number. If the input has a integer type the function is equivalent to np.max. Examples >>> a = np.array([[1, 2], [3, np.nan]])
>>> np.nanmax(a)
3.0
>>> np.nanmax(a, axis=0)
array([3.,  2.])
>>> np.nanmax(a, axis=1)
array([2.,  3.])
 When positive infinity and negative infinity are present: >>> np.nanmax([1, 2, np.nan, np.NINF])
2.0
>>> np.nanmax([1, 2, np.nan, np.inf])
inf


numpy.nanmean   numpy.nanmean(a, axis=None, dtype=None, out=None, keepdims=<no value>, *, where=<no value>)[source]

Compute the arithmetic mean along the specified axis, ignoring NaNs. Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. float64 intermediate and return values are used for integer inputs. For all-NaN slices, NaN is returned and a RuntimeWarning is raised.  New in version 1.8.0.   Parameters

aarray_like

Array containing numbers whose mean is desired. If a is not an array, a conversion is attempted.
axis{int, tuple of int, None}, optional

Axis or axes along which the means are computed. The default is to compute the mean of the flattened array.
dtypedata-type, optional

Type to use in computing the mean. For integer inputs, the default is float64; for inexact inputs, it is the same as the input dtype.
outndarray, optional

Alternate output array in which to place the result. The default is None; if provided, it must have the same shape as the expected output, but the type will be cast if necessary. See Output type determination for more details.
keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a. If the value is anything but the default, then keepdims will be passed through to the mean or sum methods of sub-classes of ndarray. If the sub-classes methods does not implement keepdims any exceptions will be raised.
wherearray_like of bool, optional

Elements to include in the mean. See reduce for details.  New in version 1.22.0.     Returns

mndarray, see dtype parameter above

If out=None, returns a new array containing the mean values, otherwise a reference to the output array is returned. Nan is returned for slices that contain only NaNs.      See also  average

Weighted average  mean

Arithmetic mean taken while not ignoring NaNs
var, nanvar

  Notes The arithmetic mean is the sum of the non-NaN elements along the axis divided by the number of non-NaN elements. Note that for floating-point input, the mean is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32. Specifying a higher-precision accumulator using the dtype keyword can alleviate this issue. Examples >>> a = np.array([[1, np.nan], [3, 4]])
>>> np.nanmean(a)
2.6666666666666665
>>> np.nanmean(a, axis=0)
array([2.,  4.])
>>> np.nanmean(a, axis=1)
array([1.,  3.5]) # may vary


numpy.nanmedian   numpy.nanmedian(a, axis=None, out=None, overwrite_input=False, keepdims=<no value>)[source]

Compute the median along the specified axis, while ignoring NaNs. Returns the median of the array elements.  New in version 1.9.0.   Parameters

aarray_like

Input array or object that can be converted to an array.
axis{int, sequence of int, None}, optional

Axis or axes along which the medians are computed. The default is to compute the median along a flattened version of the array. A sequence of axes is supported since version 1.9.0.
outndarray, optional

Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output, but the type (of the output) will be cast if necessary.
overwrite_inputbool, optional

If True, then allow use of memory of input array a for calculations. The input array will be modified by the call to median. This will save memory when you do not need to preserve the contents of the input array. Treat the input as undefined, but it will probably be fully or partially sorted. Default is False. If overwrite_input is True and a is not already an ndarray, an error will be raised.
keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a. If this is anything but the default value it will be passed through (in the special case of an empty array) to the mean function of the underlying array. If the array is a sub-class and mean does not have the kwarg keepdims this will raise a RuntimeError.    Returns

medianndarray

A new array holding the result. If the input contains integers or floats smaller than float64, then the output data-type is np.float64. Otherwise, the data-type of the output is the same as that of the input. If out is specified, that array is returned instead.      See also
mean, median, percentile

  Notes Given a vector V of length N, the median of V is the middle value of a sorted copy of V, V_sorted - i.e., V_sorted[(N-1)/2], when N is odd and the average of the two middle values of V_sorted when N is even. Examples >>> a = np.array([[10.0, 7, 4], [3, 2, 1]])
>>> a[0, 1] = np.nan
>>> a
array([[10., nan,  4.],
       [ 3.,  2.,  1.]])
>>> np.median(a)
nan
>>> np.nanmedian(a)
3.0
>>> np.nanmedian(a, axis=0)
array([6.5, 2. , 2.5])
>>> np.median(a, axis=1)
array([nan,  2.])
>>> b = a.copy()
>>> np.nanmedian(b, axis=1, overwrite_input=True)
array([7.,  2.])
>>> assert not np.all(a==b)
>>> b = a.copy()
>>> np.nanmedian(b, axis=None, overwrite_input=True)
3.0
>>> assert not np.all(a==b)


numpy.nanmin   numpy.nanmin(a, axis=None, out=None, keepdims=<no value>, initial=<no value>, where=<no value>)[source]

Return minimum of an array or minimum along an axis, ignoring any NaNs. When all-NaN slices are encountered a RuntimeWarning is raised and Nan is returned for that slice.  Parameters

aarray_like

Array containing numbers whose minimum is desired. If a is not an array, a conversion is attempted.
axis{int, tuple of int, None}, optional

Axis or axes along which the minimum is computed. The default is to compute the minimum of the flattened array.
outndarray, optional

Alternate output array in which to place the result. The default is None; if provided, it must have the same shape as the expected output, but the type will be cast if necessary. See Output type determination for more details.  New in version 1.8.0.
keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a. If the value is anything but the default, then keepdims will be passed through to the min method of sub-classes of ndarray. If the sub-classes methods does not implement keepdims any exceptions will be raised.  New in version 1.8.0.
initialscalar, optional

The maximum value of an output element. Must be present to allow computation on empty slice. See reduce for details.  New in version 1.22.0.
wherearray_like of bool, optional

Elements to compare for the minimum. See reduce for details.  New in version 1.22.0.     Returns

nanminndarray

An array with the same shape as a, with the specified axis removed. If a is a 0-d array, or if axis is None, an ndarray scalar is returned. The same dtype as a is returned.      See also  nanmax

The maximum value of an array along a given axis, ignoring any NaNs.  amin

The minimum value of an array along a given axis, propagating any NaNs.  fmin

Element-wise minimum of two arrays, ignoring any NaNs.  minimum

Element-wise minimum of two arrays, propagating any NaNs.  isnan

Shows which elements are Not a Number (NaN).  isfinite

Shows which elements are neither NaN nor infinity.
amax, fmax, maximum

  Notes NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity. Positive infinity is treated as a very large number and negative infinity is treated as a very small (i.e. negative) number. If the input has a integer type the function is equivalent to np.min. Examples >>> a = np.array([[1, 2], [3, np.nan]])
>>> np.nanmin(a)
1.0
>>> np.nanmin(a, axis=0)
array([1.,  2.])
>>> np.nanmin(a, axis=1)
array([1.,  3.])
 When positive infinity and negative infinity are present: >>> np.nanmin([1, 2, np.nan, np.inf])
1.0
>>> np.nanmin([1, 2, np.nan, np.NINF])
-inf