0

Minimal code:

import numpy as np

np.rint(0.5)   # Output is 0     OK!
np.rint(718.5) # Output is 718   OK!
np.rint(719.5) # Output is 720   WRONG!

Obviously the expected result for the last row would be 719. Any explanation?

I am running NumPy 1.19.5 and Python 3.9.1

decadenza
  • 2,380
  • 3
  • 18
  • 31
  • 2
    I believe this has been a thing since forever, See, for example [this](http://lukewrites.com/posts/rounding-decimals-in-python-or-why-doesnt-5-round-to-1/) and [this](https://stackoverflow.com/questions/10093783/rounding-error-in-python-with-non-odd-number/10093820#10093820) . – Quang Hoang Jan 11 '21 at 17:10
  • Thanks, found the Banker's rule I wasn't aware of. Problem is, as I'm working with 720p images, it causes an IndexingError as row 720 does not exist... – decadenza Jan 11 '21 at 17:17

0 Answers0