MCPcopy Create free account
hub / github.com/numpy/numpy / seterr

Function seterr

numpy/core/_ufunc_config.py:34–129  ·  view source on GitHub ↗

Set how floating-point errors are handled. Note that operations on integer scalar types (such as `int16`) are handled like floating point, and are affected by these settings. Parameters ---------- all : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional

(all=None, divide=None, over=None, under=None, invalid=None)

Source from the content-addressed store, hash-verified

32
33@set_module('numpy')
34def seterr(all=None, divide=None, over=None, under=None, invalid=None):
35 """
36 Set how floating-point errors are handled.
37
38 Note that operations on integer scalar types (such as `int16`) are
39 handled like floating point, and are affected by these settings.
40
41 Parameters
42 ----------
43 all : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional
44 Set treatment for all types of floating-point errors at once:
45
46 - ignore: Take no action when the exception occurs.
47 - warn: Print a `RuntimeWarning` (via the Python `warnings` module).
48 - raise: Raise a `FloatingPointError`.
49 - call: Call a function specified using the `seterrcall` function.
50 - print: Print a warning directly to ``stdout``.
51 - log: Record error in a Log object specified by `seterrcall`.
52
53 The default is not to change the current behavior.
54 divide : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional
55 Treatment for division by zero.
56 over : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional
57 Treatment for floating-point overflow.
58 under : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional
59 Treatment for floating-point underflow.
60 invalid : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional
61 Treatment for invalid floating-point operation.
62
63 Returns
64 -------
65 old_settings : dict
66 Dictionary containing the old settings.
67
68 See also
69 --------
70 seterrcall : Set a callback function for the 'call' mode.
71 geterr, geterrcall, errstate
72
73 Notes
74 -----
75 The floating-point exceptions are defined in the IEEE 754 standard [1]_:
76
77 - Division by zero: infinite result obtained from finite numbers.
78 - Overflow: result too large to be expressed.
79 - Underflow: result so close to zero that some precision
80 was lost.
81 - Invalid operation: result is not an expressible number, typically
82 indicates that a NaN was produced.
83
84 .. [1] https://en.wikipedia.org/wiki/IEEE_754
85
86 Examples
87 --------
88 >>> old_settings = np.seterr(all='ignore') #seterr to known value
89 >>> np.seterr(over='raise')
90 {'divide': 'ignore', 'over': 'ignore', 'under': 'ignore', 'invalid': 'ignore'}
91 >>> np.seterr(**old_settings) # reset to default

Callers 2

__enter__Method · 0.85
__exit__Method · 0.85

Calls 1

geterrFunction · 0.85

Tested by

no test coverage detected