{ } Raw JSON

bundles / scipy 1.17.1 / scipy / _lib / array_api_extra / _delegation / nan_to_num

function

scipy._lib.array_api_extra._delegation:nan_to_num

source: /scipy/_lib/array_api_extra/_delegation.py :419

Signature

def   nan_to_num ( x : Array | float | complex / fill_value : int | float = 0.0 xp : ModuleType | None = None )  →  Array

Summary

Replace NaN with zero and infinity with large finite numbers (default behaviour).

Extended Summary

If x is inexact, NaN is replaced by zero or by the user defined value in the fill_value keyword, infinity is replaced by the largest finite floating point value representable by x.dtype, and -infinity is replaced by the most negative finite floating point value representable by x.dtype.

For complex dtypes, the above is applied to each of the real and imaginary components of x separately.

Parameters

x : array | float | complex

Input data.

fill_value : 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.

xp : array_namespace, optional

The standard-compatible namespace for x. Default: infer.

Returns

: array

x, with the non-finite values replaced.

Examples

import array_api_extra as xpx
import array_api_strict as xp
xpx.nan_to_num(xp.inf)
xpx.nan_to_num(-xp.inf)
xpx.nan_to_num(xp.nan)
x = xp.asarray([xp.inf, -xp.inf, xp.nan, -128, 128])
xpx.nan_to_num(x)
y = xp.asarray([complex(xp.inf, xp.nan), xp.nan, complex(xp.nan, xp.inf)])
xpx.nan_to_num(y)

See also

array_api.isnan

Shows which elements are Not a Number (NaN).

Aliases

  • scipy.differentiate.xpx.nan_to_num