Numpy 的 allclose(~)
對給定的兩個數組執行逐元素比較,如果每對之間的所有差異都在指定的容差範圍內,則返回 True。
參數
1. x1
| array-like
第一個輸入數組。
2. x2
| array-like
第二個輸入數組。
3. rtol
| float
| optional
相對容差參數。默認情況下,rtol=0
。
4. atol
| float
| optional
絕對公差參數。默認情況下,atol
設置為一個較小的數字 (~1e-8)
5. equal_nan
| boolean
| optional
如果為 True,則涉及兩個 NaNs 的逐元素比較將計算為 True。默認情況下,equal_nan=False
。
此處,如果滿足以下條件,則逐元素比較的計算結果為 True:
absolute(a - b) <= (atol + rtol * absolute(b))
返回值
一個布爾值,指示兩個數組是否足夠"close"。
例子
基本用法
np.allclose([2,3], [5,3])
False
這裏,第一次逐元素比較 2 != 5
,因此該方法返回 False
。
指定絕對公差參數
np.allclose([6,4], [8,3], atol=2)
True
這裏是 absolute(6,8) <= 2
和 absolute(4,3) <= 2
。
指定相對容差參數
np.allclose([6,3], [4,6], rtol=0.5)
True
這裏是 absolute(6,4) <= 4*0.5
和 absolute(3,6) <= 6*0.5
。
比較NaNs
np.allclose(np.NaN, np.NaN)
False
np.allclose(np.NaN, np.NaN, equal_nan=True)
True
相關用法
- Python all方法用法及代碼示例
- Python NumPy all方法用法及代碼示例
- Python all用法及代碼示例
- Python all()用法及代碼示例
- Python arcgis.gis._impl._profile.ProfileManager.save_as用法及代碼示例
- Python arcgis.raster.functions.ccdc_analysis用法及代碼示例
- Python arcgis.geometry.functions.trim_extend用法及代碼示例
- Python arcgis.raster.analytics.sample用法及代碼示例
- Python arcgis.features.analysis.derive_new_locations用法及代碼示例
- Python arcgis.features.analyze_patterns.calculate_density用法及代碼示例
- Python arcgis.geometry.Geometry.label_point用法及代碼示例
- Python ast.MatchClass用法及代碼示例
- Python arcgis.plan_routes用法及代碼示例
- Python arcgis.mapping.forms.FormInfo用法及代碼示例
- Python arcgis.gis.UserManager.get用法及代碼示例
- Python arcgis.raster.ImageryLayerCacheManager.update_tiles用法及代碼示例
- Python arcgis.geometry.Geometry.true_centroid用法及代碼示例
- Python arcgis.gis.User.generate_direct_access_url用法及代碼示例
- Python arcgis.gis.GroupMigrationManager.create用法及代碼示例
- Python arcgis.geometry.Geometry.hull_rectangle用法及代碼示例
- Python arcgis.features.analysis.summarize_within用法及代碼示例
- Python arcgis.geometry.filters.intersects用法及代碼示例
- Python arcgis.geometry.functions.project用法及代碼示例
- Python abc.ABCMeta用法及代碼示例
- Python arcgis.raster.functions.percentile用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 NumPy | allclose method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。