bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / errstate
class
numpy:errstate
source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/__init__.py
Signature
class errstate ( ** kwargs ) Summary
Context manager for floating-point error handling.
Extended Summary
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.
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'}.
Notes
For complete documentation of the types of floating-point exceptions and treatment options, see seterr.
Examples
import numpy as np olderr = np.seterr(all='ignore') # Set error handling to known state.✓
np.arange(3) / 0. with np.errstate(divide='ignore'): np.arange(3) / 0.✓
np.sqrt(-1) with np.errstate(invalid='raise'): np.sqrt(-1)✓
np.geterr() olderr = np.seterr(**olderr) # restore original state✓
See also
- geterr
- geterrcall
- seterr
- seterrcall
Aliases
-
numpy.errstate