且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

numpy.round的奇怪行为

更新时间:2023-02-27 14:38:32

numpy舍入到最接近的偶数值:

numpy rounds to the nearest even value:

https://docs.scipy .org/doc/numpy/reference/generated/numpy.around.html#numpy.around

对于恰好位于四舍五入的十进制值中间的值,NumPy会四舍五入为最接近的偶数.因此1.5和2.5四舍五入为2.0,-0.5和0.5四舍五入为0.0,等等.

For values exactly halfway between rounded decimal values, NumPy rounds to the nearest even value. Thus 1.5 and 2.5 round to 2.0, -0.5 and 0.5 round to 0.0, etc.