numpy.geterrcall#

numpy.geterrcall()[源代码]#

返回当前用于浮点数错误的回调函数.

当浮点错误(”divide”、”over”、”under”或”invalid”之一)的错误处理设置为’call’或’log’时,由`geterrcall`返回被调用的函数或写入的日志实例.该函数或日志实例已通过`seterrcall`设置.

返回:
errobj可调用对象、日志实例或 None

当前的错误处理器.如果没有通过 seterrcall 设置处理器,则返回 None.

备注

有关浮点异常类型和处理选项的完整文档,请参见 seterr.

示例

>>> import numpy as np
>>> np.geterrcall()  # we did not yet set a handler, returns None
>>> orig_settings = np.seterr(all='call')
>>> def err_handler(type, flag):
...     print("Floating point error (%s), with flag %s" % (type, flag))
>>> old_handler = np.seterrcall(err_handler)
>>> np.array([1, 2, 3]) / 0.0
Floating point error (divide by zero), with flag 1
array([inf, inf, inf])
>>> cur_handler = np.geterrcall()
>>> cur_handler is err_handler
True
>>> old_settings = np.seterr(**orig_settings)  # restore original
>>> old_handler = np.seterrcall(None)  # restore original