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.

np.uint64 + int == ... np.float64 ??

See original GitHub issue

Is this behavior expected?

>>> print type(np.uint32(0) + int(0))
<type 'numpy.int64'>
>>> print type(np.uint64(0) + int(0))
<type 'numpy.float64'>

The latter took me by surprise!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:16 (13 by maintainers)

github_iconTop GitHub Comments

3reactions
sem-geologistcommented, Jan 31, 2016

This behaviour also buged my program. Why it couldn’t simply overrun leaving responsibility for user. Casting silently to float64 is bad… If this is “normal” behaviour, it should be at least documented in official documentation.

2reactions
NeilGirdharcommented, Jan 25, 2017

Two other solutions:

  • Make int64 + int return int64 and similarly uint64 + int return uint64. Wrap and warn on overflow just like it does when adding homogenous types.
  • Make int64 + int return a dtype of object and use Python’s int.

I prefer the first solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert ndarray from float64 to integer - python - Stack Overflow
I'm using this arr in the following examples: >>> import numpy as np >>> arr = np.array([1, ...
Read more >
Data types — NumPy v1.24 Manual
There are 5 basic numerical types representing booleans (bool), integers (int), unsigned integers (uint) floating point (float) and complex.
Read more >
NumPy: Data types - w3resource
NumPy Data types: NumPy supports a much greater variety of ... integers (int), unsigned integers (uint) floating point (float) and complex.
Read more >
NumPy: Cast ndarray to a specific dtype with astype()
List of basic data types ( dtype ) in NumPy ; uint64, u8, 64-bit unsigned integer ; float16, f2, 16-bit floating-point number ;...
Read more >
Understanding Data Types in Python
NumPy Standard Data Types¶ ; uint64, Unsigned integer (0 to 18446744073709551615) ; float_, Shorthand for float64 . ; float16, Half precision float: sign...
Read more >

github_iconTop Related Medium Post

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