[Numpy-discussion] Behavior of rint?

Matthew Brett matthew.brett at gmail.com
Fri Jan 19 05:30:05 EST 2018


Hi,

Sorry for my confusion, but I noticed (as a result of the discussion
here [1]) that np.rint and the fallback C function [2] seem to round
to even.  But - my impression was that C rint, by default, rounds down
[3].   Is numpy rint not behaving the same way as the GNU C library
rint?

In [4]: np.rint(np.arange(0.5, 11))
Out[4]: array([ 0.,  2.,  2.,  4.,  4.,  6.,  6.,  8.,  8., 10., 10.])

In [5]: np.round(np.arange(0.5, 11))
Out[5]: array([ 0.,  2.,  2.,  4.,  4.,  6.,  6.,  8.,  8., 10., 10.])

Cheers,

Matthew

[1] https://github.com/nipy/dipy/issues/1402
[2] https://github.com/numpy/numpy/blob/master/numpy/core/src/npymath/npy_math_internal.h.src#L290
[3] https://www.gnu.org/software/libc/manual/html_node/Rounding-Functions.html


More information about the NumPy-Discussion mailing list