Get the current way of handling floating-point errors. Returns ------- res : dict A dictionary with keys "divide", "over", "under", and "invalid", whose values are from the strings "ignore", "print", "log", "warn", "raise", and "call". The keys represent pos
()
| 131 | |
| 132 | @set_module('numpy') |
| 133 | def geterr(): |
| 134 | """ |
| 135 | Get the current way of handling floating-point errors. |
| 136 | |
| 137 | Returns |
| 138 | ------- |
| 139 | res : dict |
| 140 | A dictionary with keys "divide", "over", "under", and "invalid", |
| 141 | whose values are from the strings "ignore", "print", "log", "warn", |
| 142 | "raise", and "call". The keys represent possible floating-point |
| 143 | exceptions, and the values define how these exceptions are handled. |
| 144 | |
| 145 | See Also |
| 146 | -------- |
| 147 | geterrcall, seterr, seterrcall |
| 148 | |
| 149 | Notes |
| 150 | ----- |
| 151 | For complete documentation of the types of floating-point exceptions and |
| 152 | treatment options, see `seterr`. |
| 153 | |
| 154 | Examples |
| 155 | -------- |
| 156 | >>> np.geterr() |
| 157 | {'divide': 'warn', 'over': 'warn', 'under': 'ignore', 'invalid': 'warn'} |
| 158 | >>> np.arange(3.) / np.arange(3.) |
| 159 | array([nan, 1., 1.]) |
| 160 | |
| 161 | >>> oldsettings = np.seterr(all='warn', over='raise') |
| 162 | >>> np.geterr() |
| 163 | {'divide': 'warn', 'over': 'raise', 'under': 'warn', 'invalid': 'warn'} |
| 164 | >>> np.arange(3.) / np.arange(3.) |
| 165 | array([nan, 1., 1.]) |
| 166 | |
| 167 | """ |
| 168 | maskvalue = umath.geterrobj()[1] |
| 169 | mask = 7 |
| 170 | res = {} |
| 171 | val = (maskvalue >> SHIFT_DIVIDEBYZERO) & mask |
| 172 | res['divide'] = _errdict_rev[val] |
| 173 | val = (maskvalue >> SHIFT_OVERFLOW) & mask |
| 174 | res['over'] = _errdict_rev[val] |
| 175 | val = (maskvalue >> SHIFT_UNDERFLOW) & mask |
| 176 | res['under'] = _errdict_rev[val] |
| 177 | val = (maskvalue >> SHIFT_INVALID) & mask |
| 178 | res['invalid'] = _errdict_rev[val] |
| 179 | return res |
| 180 | |
| 181 | |
| 182 | @set_module('numpy') |