首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

numpy.testing.utils

assert_(val, msg='') Assert that works in release mode. assert_almost_equal(actual, desired, decimal=7, err_msg='', verbose=True) Raise an assertion if two items are not equal up to desired precision. The test is equivalent to abs(desired-actual) < 0.5 * 10**(-decimal) Given two objects (numbers or ndarrays), check that all elements of these objects are almost equal. An exception is raised at conflicting values. For ndarrays this delegates to assert_array_almost_equal Parameters ---------- actual : number or ndarray The object to check. desired : number or ndarray The expected object. decimal : integer (decimal=7) desired precision err_msg : string The error message to be printed in case of failure. verbose : bool If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_array_almost_equal: compares array_like objects assert_equal: tests objects for equality Examples -------- >>> npt.assert_almost_equal(2.3333333333333, 2.33333334) >>> npt.assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) ... <type 'exceptions.AssertionError'>: Items are not equal: ACTUAL: 2.3333333333333002 DESIRED: 2.3333333399999998 >>> npt.assert_almost_equal(np.array([1.0,2.3333333333333]), np.array([1.0,2.33333334]), decimal=9) ... <type 'exceptions.AssertionError'>: Arrays are not almost equal <BLANKLINE> (mismatch 50.0%) x: array([ 1. , 2.33333333]) y: array([ 1. , 2.33333334]) assert_approx_equal(actual, desired, significant=7, err_msg='', verbose=True) Raise an assertion if two items are not equal up to significant digits. Given two numbers, check that they are approximately equal. Approximately equal is defined as the number of significant digits that

03

python Exception(异常处

python异常:    python在运行时错误称为异常        语法错误:软件的结构上有错误而导致不能被解释器解释或不能被编译器编译。        逻辑错误:由于不完整或不合法的输入所致,也可能是逻辑无法生成、计算或者出结果需要的过程无法执行等。    默认情况下:python脚本执行过程中出现异常后,脚本执行将被终止。    python 异常是一个对象,表示错误或意外的情况    在python检测到一个错误时,将触发一个异常:        python可以通过异常传导机制传递一个异常对象,发出一个异常情况出现的信号。        程序员也可以在代码中托运触发异常    python异常也可以理解为:程序出现了错误,而在正常控制流以外采取的行为        第一阶段:解释器触发异常,此时当前程序流将被打断。        第二阶段:异常处理,如忽略非致命错误、减轻错误带来的影响等。 异常的功用    错误处理:        python的默认处理:停止程序,打印错误消息        使用try语句处理异常,并从异常中恢复    事件通知:        用于发出有效状态信号    特殊情况处理:        无法调整代码去处理的场景    终止行为:        try/finally语句可确保执行必需的结束处理机制    非常规控制流程:        异常是一种高级跳转(goto)机制 异常对象    python异常是内置的经典类exception的子类的实例        为了向后兼容,python还允许使用字符串或任何经典类实例        python2.5之后,exception是从BaseException继承的新式类(即exception的父类是BaseException类)    python自身引发的所有异常都是Exception的子类的实例    大多的标准异常都是由StandardError派生的,其有3个抽象的子类        ArithmeticError:由于算术错误而引发的异常基类;包括:OverflowError、ZeroDivisionError、FloatingPorintError        LookupError:容器在接收到一个无效的键或索引时引发的异常的基类;包括:IndexError、KeyError        EnvironmentError:由于外部原因而导致的异常的基类;包括:IOError、OSError、WindowsError 标准异常类    AssertionError:断言语句失败    AttributeError:属性引用或赋值失败    FloatingPointError:浮点型运算失败    IOError:I/O操作失败    ImportError:import语句不能找到要导入的模块,或者不能找到该模块特别请求的名称。    IndentationError:解析器遇到了一个由于错误的缩进而引发的语法错误    IndexError:用来索引序列的整数超出了范围。    KeyError:用来索引映射的键不在映射中    KeyboardInterrupt:用户按了中断键(ctrl+c、ctrl+break、delete键)    MemoryError:运算耗尽内存    NameError:引用了一个不存在的变量名    NotImplementedError:由抽象基类引发的异常,用于指示一个具体的子类必须覆盖一个方法    OSError:由模块os中的函数引发的异常,用来指示平台相关的错误    OverflowError:整数运算的结果太大导致溢出    SyntaxError:语法错误    SystemError:python解释器本身或某些扩展模块中的内部错误     TypeError:对某对象执行了不支持的操作    UnboundLocalError:引用未绑定值的本地变量     UnicodeError:在Unicode的字符串之间进行转换时发生的错误     ValueError:应用于某个对象的操作或函数,这个对象具有正确的类型,但确有不适当的值    WindowsError:模块OS中的函数引发的异常,用于指示与windowsSHUDR QAYK     ZeroDivisionError:除数为0引发的异常   检测和处理异常:    异常通过try语句来检测:任何在try语句块中的代码都会被监测,以检查有无异常发生。    tr语句主要有两种形式:        try-except:检测和处理异常            可以有多个e

03

扫码

添加站长 进交流群

领取专属 10元无门槛券

手把手带您无忧上云

扫码加入开发者社群

相关资讯

热门标签

活动推荐

    运营活动

    活动名称
    广告关闭
    领券