MCPcopy Index your code
hub / github.com/numpy/numpy / _replace_nan

Function _replace_nan

numpy/lib/_nanfunctions_impl.py:70–112  ·  view source on GitHub ↗

If `a` is of inexact type, make a copy of `a`, replace NaNs with the `val` value, and return the copy together with a boolean mask marking the locations where NaNs were present. If `a` is not of inexact type, do nothing and return `a` together with a mask of None. Note that sca

(a, val)

Source from the content-addressed store, hash-verified

68 return y
69
70def _replace_nan(a, val):
71 """
72 If `a` is of inexact type, make a copy of `a`, replace NaNs with
73 the `val` value, and return the copy together with a boolean mask
74 marking the locations where NaNs were present. If `a` is not of
75 inexact type, do nothing and return `a` together with a mask of None.
76
77 Note that scalars will end up as array scalars, which is important
78 for using the result as the value of the out argument in some
79 operations.
80
81 Parameters
82 ----------
83 a : array-like
84 Input array.
85 val : float
86 NaN values are set to val before doing the operation.
87
88 Returns
89 -------
90 y : ndarray
91 If `a` is of inexact type, return a copy of `a` with the NaNs
92 replaced by the fill value, otherwise return `a`.
93 mask: {bool, None}
94 If `a` is of inexact type, return a boolean mask marking locations of
95 NaNs, otherwise return None.
96
97 """
98 a = np.asanyarray(a)
99
100 if a.dtype == np.object_:
101 # object arrays do not support `isnan` (gh-9009), so make a guess
102 mask = np.not_equal(a, a, dtype=bool)
103 elif issubclass(a.dtype.type, np.inexact):
104 mask = np.isnan(a)
105 else:
106 mask = None
107
108 if mask is not None:
109 a = np.array(a, subok=True, copy=True)
110 np.copyto(a, val, where=mask)
111
112 return a, mask
113
114
115def _copyto(a, val, mask):

Callers 11

test__replace_nanFunction · 0.90
nanminFunction · 0.85
nanmaxFunction · 0.85
nanargminFunction · 0.85
nanargmaxFunction · 0.85
nansumFunction · 0.85
nanprodFunction · 0.85
nancumsumFunction · 0.85
nancumprodFunction · 0.85
nanmeanFunction · 0.85
nanvarFunction · 0.85

Calls

no outgoing calls

Tested by 1

test__replace_nanFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…