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)
| 68 | return y |
| 69 | |
| 70 | def _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 | |
| 115 | def _copyto(a, val, mask): |
no outgoing calls
searching dependent graphs…