question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incompatible numpy.float64.__round__()

See original GitHub issue

round(x) (i.e. object.__round__(self)) is expected to return an int, but for numpy floats, it returns a numpy float.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pepalogikcommented, Feb 24, 2014

Right, I am using Python 3. I did not know that the round behavior had changed because I have never been using Python 2.

>>> round(1.5)
2

The NumPy floats behave just like ordinary Python floats, until it gets to rounding. This had caused a hard-to-find bug in my project.

0reactions
sebergcommented, Oct 4, 2021

We changed float scalar rounding a while ago to align with Python (although not quite sure which NumPy version).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strange behavior of numpy.round - python - Stack Overflow
1 Answer 1 ... For values exactly halfway between rounded decimal values, NumPy rounds to the nearest even value. Thus 1.5 and 2.5...
Read more >
Issue 36879: bug with round() and "numpy floats" - Issue Tracker
round() delegates to class.__round__, so what's happening here is that numpy's float implements __round__ in a way it returns a float.
Read more >
NumPy 1.20.0 Release Notes
In this case, the Python version float(123) or int(12.) is normally preferable, although the NumPy version may be useful for consistency with NumPy...
Read more >
numpy.ndarray.round — NumPy v1.24 Manual
ndarray.round(decimals=0, out=None)#. Return a with each element rounded to the given number of decimals. Refer to numpy.around for full documentation.
Read more >
numpy.ndarray.shape — NumPy v1.24 Manual
shape = (-1,) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: Incompatible shape for in-place modification. Use `.reshape ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found