Numpy 的 around(~)
方法對輸入數組中的值進行向上和向下舍入。
參數
1. a
| array_like
輸入數組。
2. decimals
| int
| optional
要舍入的小數位數。請注意, decimals=1
意味著像 1.52
這樣的值將四舍五入為 1.5
。另一方麵,decimals=-1
會將 13 等值舍入為 10(即最接近的第 10 位)。
返回值
如果 a
是標量,則返回標量,否則返回 Numpy 數組。
警告
以 5 結尾的數字將向下舍入。
2.5
和 3.45
等數字將分別向下舍入為 2
和 3.4
,而不是向上舍入。
例子
四舍五入到最接近的整數
x = np.array([2.3,2.5,2.7])
np.round(x)
array([2., 2., 3.])
將值四舍五入到小數點後第一位
將1
設置為第二個參數:
x = np.array([2.3,2.5,2.7])
np.around(x,1)
array([2.3, 2.5, 2.7])
將值四舍五入到最接近的 10 位
將-1
設置為第二個參數:
x = np.array([4,12,16])
np.around(x,-1)
array([ 0, 10, 20])
相關用法
- 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 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 arcgis.raster.functions.percentile用法及代碼示例
- Python arcgis.raster.ImageryLayer.save用法及代碼示例
- Python arcgis.geoanalytics.summarize_data.reconstruct_tracks用法及代碼示例
- Python arcgis.gis.admin.LivingAtlas用法及代碼示例
- Python arcgis.features.Table.get_unique_values用法及代碼示例
- Python arcgis.realtime.velocity.feeds.RunInterval用法及代碼示例
- Python arcgis.mapping.WebMap.print用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 NumPy | around method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。