Numpy surprises

From Tech
Revision as of 16:53, 11 December 2025 by Joosteto (talk | contribs) (Created page with "New in numpy version 2: numpy int types aren't promoted to bigger types. >>> np.uint8(1) + 255 <python-input-21>:1: RuntimeWarning: overflow encountered in scalar add...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

New in numpy version 2: numpy int types aren't promoted to bigger types.

   >>> np.uint8(1) + 255
   <python-input-21>:1: RuntimeWarning: overflow encountered in scalar add
   np.uint8(0)
   >>> np.__version__
   '2.2.4'


The old numpy 1.24 used to promote numpy int types to 64-bit:

   >>> type(np.uint8(1) + 1)
   <class 'numpy.int64'>
   >>> np.__version__
   '1.24.2'