[Numpy-discussion] round / set_printoptions discrepancy
deak.andris at gmail.com
Fri Sep 13 07:23:57 EDT 2019
On Fri, Sep 13, 2019 at 12:58 PM Irvin Probst
<irvin.probst at ensta-bretagne.fr> wrote:
> Is it expected/documented that np.round and np.set_printoptions do not
> output the same result on screen ?
> I tumbled into this running this code:
> import numpy as np
> mes = np.array([
> [16.06, 16.13, 16.06, 16.00, 16.06, 16.00, 16.13, 16.00]
> avg = np.mean(mes, axis=1)
> print(np.round(avg, 2))
> Which outputs:
> Is that worth a bug report or did I miss something ? I've been able to
> reproduce this on many windows/linux PCs with python/numpy releases from
> 2017 up to last week.
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
I just want to add that you can use literal 16.055 to reproduce this:
>>> import numpy as np
I would think it has to do with "round to nearest even":
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).
More information about the NumPy-Discussion