如果輸入數組中的所有元素的計算結果均為 True
,Numpy 的 all(~)
方法將返回 True
。請注意,缺失值 (np.NaN) 將計算為 True。
參數
1. a
| array_like
輸入數組。
2. axis
| int
| optional
對於二維數組,允許的值如下:
軸 |
說明 |
---|---|
0 |
按列執行 |
1 |
按行執行 |
|
在整個DataFrame上執行 |
默認情況下,axis=None
。
3. out
| Numpy array
| optional
您可以將計算結果放入 out
指定的數組中,而不是創建新數組。
4. where
| boolean
的array
| optional
標記為 False 的值將被忽略,即它們的原始值將未被初始化。如果指定了 out 參數,行為會略有不同 - 原始值將保持不變。
返回值
如果 axis=None,則返回布爾值。否則,返回一個 Numpy 布爾數組。
例子
基本用法
np.all([True, False, True])
False
np.all([5, 0, 0])
False
二維數組
考慮以下二維數組:
a = np.array([[0,np.NaN], [0,2]])
a
array([[ 0., nan],
[ 0., 2.]])
所有值
np.all(a)
False
按列
np.all(a, axis=0)
array([False, True])
逐行
np.all(a, axis=1) # remember, NaN still evaluates to True
array([False, False])
相關用法
- Python all方法用法及代碼示例
- Python all用法及代碼示例
- Python all()用法及代碼示例
- Python NumPy allclose方法用法及代碼示例
- 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 | all method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。