jax.numpy.nan_to_num#
- jax.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
LAX-backend implementation of
numpy.nan_to_num()
.Original docstring below.
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 byx.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:
x (scalar or array_like) – Input data.
copy (bool, 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.
nan (int, float, optional) – Value to be used to fill NaN values. If no value is passed then NaN values will be replaced with 0.0.
posinf (int, 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.
neginf (int, 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.
- Returns:
out – x, with the non-finite values replaced. If copy is False, this may be x itself.
- Return type:
ndarray