[Numpy-discussion] round / set_printoptions discrepancy
Philip Hodge
hodge at stsci.edu
Fri Sep 13 08:05:27 EDT 2019
On 9/13/19 7:23 AM, Andras Deak wrote:
> I just want to add that you can use literal 16.055 to reproduce this:
>>>> import numpy as np
>>>> np.set_printoptions(precision=2)
>>>> np.array([16.055]).round(2)
> array([16.06])
>>>> np.array([16.055])
> array([16.05])
>
> I would think it has to do with "round to nearest even":
>>>> np.array(16.055)
> array(16.05)
>>>> np.array(16.065)
> array(16.07)
>>>> np.array(16.065).round(2)
> 16.07
>
> But it's as if `round` rounded decimal digits upwards (16.055 ->
> 16.06, 16.065 -> 16.07), whereas the `repr` rounded to the nearest
> odd(!) digit (16.055 -> 16.05, 16.065 -> 16.07). Does this make any
> sense? I'm on numpy 1.17.2.
> (Scalars or 1-length 1d arrays don't seem to make a difference).
> Regards,
>
> András
Isn't that just for consistency with Python 3 round()? I agree that the
discrepancy with np.set_printoptions is not necessarily expected, except
possibly for backwards compatibility.
Phil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20190913/5fff4bb0/attachment.html>
More information about the NumPy-Discussion
mailing list