本文簡要介紹 python 語言中 numpy.testing.assert_equal
的用法。
用法:
testing.assert_equal(actual, desired, err_msg='', verbose=True)
如果兩個對象不相等,則引發AssertionError。
給定兩個對象(標量、列表、元組、字典或 numpy 數組),檢查這些對象的所有元素是否相等。在第一個衝突值處引發異常。
當actual 和desired 之一是標量而另一個是數組 時,該函數檢查數組 對象的每個元素是否等於標量。
此函數處理NaN 比較,就好像NaN 是“normal” 數字一樣。也就是說,如果兩個對象的 NaNs 位於相同位置,則不會引發 AssertionError。這與 NaN 的 IEEE 標準形成鮮明對比,該標準規定,NaN 與任何內容相比都必須返回 False。
- actual: array_like
要檢查的對象。
- desired: array_like
預期的對象。
- err_msg: str,可選
失敗時要打印的錯誤消息。
- verbose: 布爾型,可選
如果為 True,則將衝突值附加到錯誤消息中。
- AssertionError
如果實際和期望不相等。
參數:
拋出:
例子:
>>> np.testing.assert_equal([4,5], [4,6]) Traceback (most recent call last): ... AssertionError: Items are not equal: item=1 ACTUAL: 5 DESIRED: 6
以下比較不會引發異常。輸入中有NaNs,但它們位於相同的位置。
>>> np.testing.assert_equal(np.array([1.0, 2.0, np.nan]), [1, 2, np.nan])
相關用法
- Python numpy testing.assert_warns用法及代碼示例
- Python numpy testing.assert_array_almost_equal_nulp用法及代碼示例
- Python numpy testing.assert_array_less用法及代碼示例
- Python numpy testing.assert_raises用法及代碼示例
- Python numpy testing.assert_almost_equal用法及代碼示例
- Python numpy testing.assert_approx_equal用法及代碼示例
- Python numpy testing.assert_allclose用法及代碼示例
- Python numpy testing.assert_string_equal用法及代碼示例
- Python numpy testing.assert_array_max_ulp用法及代碼示例
- Python numpy testing.assert_array_equal用法及代碼示例
- Python numpy testing.assert_array_almost_equal用法及代碼示例
- Python numpy testing.rundocs用法及代碼示例
- Python numpy testing.decorators.slow用法及代碼示例
- Python numpy testing.suppress_warnings用法及代碼示例
- Python numpy testing.run_module_suite用法及代碼示例
- Python numpy testing.decorators.setastest用法及代碼示例
- Python numpy tensordot用法及代碼示例
- Python numpy trim_zeros用法及代碼示例
- Python numpy trace用法及代碼示例
- Python numpy tri用法及代碼示例
- Python numpy true_divide用法及代碼示例
- Python numpy transpose用法及代碼示例
- Python numpy tile用法及代碼示例
- Python numpy tanh用法及代碼示例
- Python numpy trapz用法及代碼示例
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.testing.assert_equal。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。