热门
最新
红包
立Flag
投票
同城
我的
发布
python 奇技淫巧之round函数:
python3.5的doc中,文档变成了“values are rounded to the closest multiple of 10 to the power minus ndigits; if two multiples are equally close, rounding is done toward the even choice.” 如果距离两边一样远,会保留到偶数的一边。比如round(0.5)和round(-0.5)都会保留到0,而round(1.5)会保留到2。
https://www.jb51.net/article/189084.htm
一个简单的方法实现如下功能:一组列表中,间隔在x以内的数据认为是同一组数据,如何去冗余呢?
使用round函数,比如说,认为间隔为0.3的数据为同一个数据,a=0.451,b=0.149, round(a/0.3)=2, round(b/0.3)=1,这样就可以把两个数据区分开来了。反之,如果二者间隔在0.3以内,除以0.3的商一致。
CSDN App 扫码分享
评论
1
打赏
- 复制链接
- 举报
下一条:
又是刷OJ的一天