本文簡要介紹 python 語言中  numpy.allclose  的用法。
- 用法:- numpy.allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)
- 如果兩個數組在容差內按元素相等,則返回 True。 - 公差值是正的,通常是非常小的數字。將相對差 (rtol * abs(b)) 和絕對差 atol 相加以與 a 和 b 之間的絕對差進行比較。 - NaNs 如果它們在同一個地方並且如果 - equal_nan=True被視為相等。如果 Inf 在兩個數組中位於相同的位置並且具有相同的符號,則它們被視為相等。- a, b: array_like
- 要比較的輸入數組。 
- rtol: 浮點數
- 相對容差參數(見注釋)。 
- atol: 浮點數
- 絕對容差參數(見注釋)。 
- equal_nan: bool
- 是否比較 NaN 相等。如果為 True,則 a 中的 NaN 將被視為等於輸出數組中 b 中的 NaN。 
 
- allclose: bool
- 如果兩個數組在給定的容差範圍內相等,則返回 True;否則為假。 
 
 - 參數:- 返回:- 注意:- 如果以下等式按元素為 True,則 allclose 返回 True。 - 絕對(a - b)<=(atol + rtol * 絕對(b)) - 上式不對稱a和b, 以便 - allclose(a, b)可能不同於- allclose(b, a)在一些罕見的情況下。- 的比較a和b使用標準廣播,這意味著a和b不需要具有相同的形狀,以便 - allclose(a, b)評估為真。對於numpy.equal但不是numpy.array_equal.- allclose沒有為非數字數據類型定義。為此,- bool被視為數字數據類型。- 例子:- >>> np.allclose([1e10,1e-7], [1.00001e10,1e-8]) False >>> np.allclose([1e10,1e-8], [1.00001e10,1e-9]) True >>> np.allclose([1e10,1e-8], [1.0001e10,1e-9]) False >>> np.allclose([1.0, np.nan], [1.0, np.nan]) False >>> np.allclose([1.0, np.nan], [1.0, np.nan], equal_nan=True) True
相關用法
- Python numpy all用法及代碼示例
- Python numpy asscalar用法及代碼示例
- Python numpy any用法及代碼示例
- Python numpy ascontiguousarray用法及代碼示例
- Python numpy asarray_chkfinite用法及代碼示例
- Python numpy argpartition用法及代碼示例
- Python numpy arctan用法及代碼示例
- Python numpy array用法及代碼示例
- Python numpy array_repr用法及代碼示例
- Python numpy arccos用法及代碼示例
- Python numpy add用法及代碼示例
- Python numpy around用法及代碼示例
- Python numpy array2string用法及代碼示例
- Python numpy atleast_1d用法及代碼示例
- Python numpy asanyarray用法及代碼示例
- Python numpy arctan2用法及代碼示例
- Python numpy angle用法及代碼示例
- Python numpy arctanh用法及代碼示例
- Python numpy apply_over_axes用法及代碼示例
- Python numpy arccosh用法及代碼示例
- Python numpy arange用法及代碼示例
- Python numpy argsort用法及代碼示例
- Python numpy asarray用法及代碼示例
- Python numpy array_equiv用法及代碼示例
- Python numpy apply_along_axis用法及代碼示例
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.allclose。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
