numpy.nan_to_num

numpy.nan_to_num(x)

Replace nan with zero and inf with large numbers.

Parameters:

x : array_like

Input data.

Returns:

out : ndarray

Array with the same shape and dtype as x. Nan is replaced by zero, and inf (-inf) is replaced by the largest (smallest) floating point value that fits in the output dtype.

Examples

>>> 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])

Previous topic

numpy.minimum

Next topic

numpy.real_if_close

This Page

Quick search