package np

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type tag = [
  1. | `Errstate
]
type t = [ `Errstate | `Object ] Obj.t
val of_pyobject : Py.Object.t -> t
val to_pyobject : [> tag ] Obj.t -> Py.Object.t
val create : ?call:Py.Object.t -> ?kwargs:(string * Py.Object.t) list -> unit -> t

errstate( **kwargs)

Context manager for floating-point error handling.

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:: 1.17.0 `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.

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'.

See Also -------- seterr, geterr, seterrcall, geterrcall

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

Examples -------- >>> from collections import OrderedDict >>> olderr = np.seterr(all='ignore') # Set error handling to known state.

>>> np.arange(3) / 0. array(nan, inf, inf) >>> with np.errstate(divide='warn'): ... np.arange(3) / 0. array(nan, inf, inf)

>>> np.sqrt(-1) nan >>> 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:

>>> OrderedDict(sorted(np.geterr().items())) OrderedDict(('divide', 'ignore'), ('invalid', 'ignore'), ('over', 'ignore'), ('under', 'ignore'))

val to_string : t -> string

Print the object to a human-readable representation.

val show : t -> string

Print the object to a human-readable representation.

val pp : Stdlib.Format.formatter -> t -> unit

Pretty-print the object to a formatter.