# nan_to_num#

ivy.nan_to_num(x, /, *, copy=True, nan=0.0, posinf=None, neginf=None, out=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.

Parameters:
• x (`Union`[`Array`, `NativeArray`]) – Array input.

• copy (`bool`) – Whether to create a copy of x (True) or to replace values in-place (False). (default: `True`) The in-place operation only occurs if casting to an array does not require a copy. Default is True.

• nan (`Union`[`float`, `int`]) – Value to be used to fill NaN values. If no value is passed then NaN values (default: `0.0`) will be replaced with 0.0.

• posinf (`Optional`[`Union`[`int`, `float`]]) – Value to be used to fill positive infinity values. If no value is passed (default: `None`) then positive infinity values will be replaced with a very large number.

• neginf (`Optional`[`Union`[`int`, `float`]]) – Value to be used to fill negative infinity values. (default: `None`) If no value is passed then negative infinity values will be replaced with a very small (or negative) number.

• out (`Optional`[`Array`]) – optional output array, for writing the result to. (default: `None`)

Return type:

`Array`

Returns:

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

Examples

```>>> x = ivy.array([1, 2, 3, nan])
>>> ivy.nan_to_num(x)
ivy.array([1.,    1.,   3.,   0.0])
>>> x = ivy.array([1, 2, 3, inf])
>>> ivy.nan_to_num(x, posinf=5e+100)
ivy.array([1.,   2.,   3.,   5e+100])
```
Array.nan_to_num(self, /, *, copy=True, nan=0.0, posinf=None, neginf=None, out=None)#

ivy.Array instance method variant of ivy.nan_to_num. This method simply wraps the function, and so the docstring for ivy.nan_to_num also applies to this method with minimal changes.

Parameters:
• self (`Array`) – Array input.

• copy (`bool`) – Whether to create a copy of x (True) or to replace values in-place (False). (default: `True`) The in-place operation only occurs if casting to an array does not require a copy. Default is True.

• nan (`Union`[`float`, `int`]) – Value to be used to fill NaN values. If no value is passed then NaN values (default: `0.0`) will be replaced with 0.0.

• posinf (`Optional`[`Union`[`int`, `float`]]) – Value to be used to fill positive infinity values. If no value is passed (default: `None`) then positive infinity values will be replaced with a very large number.

• neginf (`Optional`[`Union`[`int`, `float`]]) – Value to be used to fill negative infinity values. (default: `None`) If no value is passed then negative infinity values will be replaced with a very small (or negative) number.

• out (`Optional`[`Array`]) – optional output array, for writing the result to. (default: `None`)

Return type:

`Array`

Returns:

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

Examples

```>>> x = ivy.array([1, 2, 3, nan])
>>> x.nan_to_num()
ivy.array([1.,    1.,   3.,   0.0])
>>> x = ivy.array([1, 2, 3, inf])
>>> x.nan_to_num(posinf=5e+100)
ivy.array([1.,   2.,   3.,   5e+100])
```
Container.nan_to_num(self, /, *, copy=True, nan=0.0, posinf=None, neginf=None, out=None)#

ivy.Container instance method variant of ivy.nan_to_num. This method simply wraps the function, and so the docstring for ivy.nan_to_num also applies to this method with minimal changes.

Parameters:
• self (`Container`) – Input container with array items.

• copy (`bool`) – Whether to create a copy of x (True) or to replace values in-place (False). (default: `True`) The in-place operation only occurs if casting to an array does not require a copy. Default is True.

• nan (`Union`[`float`, `int`]) – Value to be used to fill NaN values. If no value is passed then NaN values (default: `0.0`) will be replaced with 0.0.

• posinf (`Optional`[`Union`[`int`, `float`]]) – Value to be used to fill positive infinity values. If no value is passed (default: `None`) then positive infinity values will be replaced with a very large number.

• neginf (`Optional`[`Union`[`int`, `float`]]) – Value to be used to fill negative infinity values. (default: `None`) If no value is passed then negative infinity values will be replaced with a very small (or negative) number.

• out (`Optional`[`Container`]) – optional output container, for writing the result to. (default: `None`)

Return type:

`Container`

Returns:

ret – Container including arrays with replaced non-finite elements.

Examples

```>>> a = ivy.array([1., 2, 3, ivy.nan], dtype="float64")
>>> b = ivy.array([1., 2, 3, ivy.inf], dtype="float64")
>>> x = ivy.Container(a=a, b=b)
>>> ret = x.nan_to_num(posinf=5e+100)
>>> print(ret)
{
a: ivy.array([1., 2., 3., 0.]),
b: ivy.array([1.e+000, 2.e+000, 3.e+000, 5.e+100])
}
```