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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。