np.around() 用法


功能:四舍五入取值,常用在逻辑回归值为 0 或 1 中

def around(a: Union[ndarray, Iterable, int, float],
decimals: Optional[int] = 0,
out: Optional[ndarray] = None) -> Any

参数:

  • a: 输入列表或矩阵
  • decimals: 对输入近似后保留小数点后n位,默认为0
  • out:可选参数,用于保存近似返回结果

实例:

>>> np.around([0.37, 1.64])
array([ 0.,  2.])
>>> np.around([0.37, 1.64], decimals=1)
array([ 0.4,  1.6])
>>> np.around([.5, 1.5, 2.5, 3.5, 4.5]) # rounds to nearest even value
array([ 0.,  2.,  2.,  4.,  4.])
>>> np.around([1,2,3,11], decimals=1) # ndarray of ints is returned
array([ 1,  2,  3, 11])
>>> np.around([1,2,3,11], decimals=-1)
array([ 0,  0,  0, 10])


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM