nan_to_num

Contents

nan_to_num#

class saiunit.math.nan_to_num(x, nan=None, posinf=None, neginf=None, **kwargs)#

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:
  • x (Array | ndarray | bool | number | bool | int | float | complex | saiunit.Quantity) – Input data.

  • nan (float | saiunit.Quantity) – Value to be used to fill NaN values. If no value is passed then NaN values will be replaced with 0.0.

  • posinf (float | saiunit.Quantity) – 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 (float | saiunit.Quantity) – 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:

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

Return type:

Array | saiunit.Quantity

Examples

>>> import saiunit as u
>>> import jax.numpy as jnp
>>> a = [1.0, jnp.nan, jnp.inf] * u.meter
>>> u.math.nan_to_num(a)