This is a pre-release version (latest). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy latest / numpy / seterr

function

numpy:seterr

source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/_core/_ufunc_config.py :19

Signature

def   seterr ( all = None divide = None over = None under = None invalid = None )

Summary

Set how floating-point errors are handled.

Extended Summary

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

Set treatment for all types of floating-point errors at once:

  • ignore: Take no action when the exception occurs.

  • warn: Print a RuntimeWarning (via the Python warnings module).

  • raise: Raise a FloatingPointError.

  • call: Call a function specified using the seterrcall function.

  • print: Print a warning directly to stdout.

  • log: Record error in a Log object specified by seterrcall.

The default is not to change the current behavior.

divide : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional

Treatment for division by zero.

over : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional

Treatment for floating-point overflow.

under : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional

Treatment for floating-point underflow.

invalid : {'ignore', 'warn', 'raise', 'call', 'print', 'log'}, optional

Treatment for invalid floating-point operation.

Returns

old_settings : dict

Dictionary containing the old settings.

Notes

The floating-point exceptions are defined in the IEEE 754 standard [1]:

  • Division by zero: infinite result obtained from finite numbers.

  • Overflow: result too large to be expressed.

  • Underflow: result so close to zero that some precision was lost.

  • Invalid operation: result is not an expressible number, typically indicates that a NaN was produced.

[1]

https://en.wikipedia.org/wiki/IEEE_754

Examples

import numpy as np
orig_settings = np.seterr(all='ignore')  # seterr to known value
np.int16(32000) * np.int16(3)
np.seterr(over='raise')
old_settings = np.seterr(all='warn', over='raise')
np.int16(32000) * np.int16(3)
old_settings = np.seterr(all='print')
np.geterr()
np.int16(32000) * np.int16(3)
np.seterr(**orig_settings)  # restore original

See also

errstate
geterr
geterrcall
seterrcall

Set a callback function for the 'call' mode.

Aliases

  • numpy.seterr

Referenced by