numpy.nan_to_num(x, copy=True)
[source]
Replace nan with zero and inf with large finite numbers.
If x
is inexact, NaN is replaced by zero, and infinity and -infinity replaced by the respectively largest and most negative finite floating point values representable by x.dtype
.
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: |
x : array_like Input data. copy : bool, optional Whether to create a copy of New in version 1.13. |
---|---|
Returns: |
out : ndarray
|
See also
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity.
>>> 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, -1.28000000e+002, 1.28000000e+002]) >>> y = np.array([complex(np.inf, np.nan), np.nan, complex(np.nan, np.inf)]) >>> np.nan_to_num(y) array([ 1.79769313e+308 +0.00000000e+000j, 0.00000000e+000 +0.00000000e+000j, 0.00000000e+000 +1.79769313e+308j])
© 2008–2017 NumPy Developers
Licensed under the NumPy License.
https://docs.scipy.org/doc/numpy-1.14.2/reference/generated/numpy.nan_to_num.html