numpy 指定浮点数的小数位数
作者:互联网
问题来源
做GUI的时候发现数据太长了,显示出来不好看,所以有这个需求
numpy.around函数
原型
numpy.around(a, decimals=0, out=None)
参数
- a:要转换的np数组
- decimals:要保留的位数,默认为0
- out :Alternative output array in which to place the result. It must have the same shape as the expected output, but the type of the output values will be cast if necessary. See doc.ufuncs (Section “Output arguments”) for details.(没用到不知道是啥,这英文也没看懂)
返回值
- 和输入数组一样大小的np数组,里面的每个元素都保留了decimals位小数
示例
>>> np.around([1.23,4.56,7.89])
array([1.,4.,7])
>>> np.around([1.23,4.56,7.89], decimals=1)
array([1.2,4.6,7.9])
>>> np.around([1.23,4.56,7.89], decimals=2)
array([1.23,4.56,7.89])
标签:around,numpy,浮点数,7.89,np,小数位,array,4.56,decimals 来源: https://www.cnblogs.com/2944014083-zhiyu/p/14856136.html