numpy 1.22.4 Pypi GitHub Homepage
Other Docs
NotesParametersBackRef
errstate(**kwargs)

Using an instance of errstate as a context manager allows statements in that context to execute with a known error handling behavior. Upon entering the context the error handling is set with seterr and seterrcall , and upon exiting it is reset to what it was before.

versionchanged

:None:None:`errstate` is also usable as a function decorator, saving a level of indentation if an entire function is wrapped. See :py:class:`contextlib.ContextDecorator` for more information.

Notes

For complete documentation of the types of floating-point exceptions and treatment options, see seterr .

Parameters

kwargs : {divide, over, under, invalid}

Keyword arguments. The valid keywords are the possible floating-point exceptions. Each keyword should have a string value that defines the treatment for the particular error. Possible values are {'ignore', 'warn', 'raise', 'call', 'print', 'log'}.

Context manager for floating-point error handling.

See Also

geterr
geterrcall
seterr
seterrcall

Examples

This example is valid syntax, but we were not able to check execution
>>> olderr = np.seterr(all='ignore')  # Set error handling to known state.
This example is valid syntax, but we were not able to check execution
>>> np.arange(3) / 0.
array([nan, inf, inf])
This example is valid syntax, but we were not able to check execution
>>> with np.errstate(divide='warn'):
...  np.arange(3) / 0. array([nan, inf, inf])
This example is valid syntax, but we were not able to check execution
>>> np.sqrt(-1)
nan
This example is valid syntax, but we were not able to check execution
>>> with np.errstate(invalid='raise'):
...  np.sqrt(-1) Traceback (most recent call last): File "<stdin>", line 2, in <module> FloatingPointError: invalid value encountered in sqrt

Outside the context the error handling behavior has not changed:

This example is valid syntax, but we were not able to check execution
>>> np.geterr()
{'divide': 'ignore', 'over': 'ignore', 'under': 'ignore', 'invalid': 'ignore'}
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

numpy.errstate numpy.seterr dask.array.ufunc.power scipy.special._ufuncs.errstate dask.array.ufunc.float_power

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/__init__.py#None
type: <class 'type'>
Commit: