Numpy surprises: Difference between revisions

From Tech
Jump to navigationJump to search
Content deleted Content added
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..."
 
No edit summary
Line 1: Line 1:
New in numpy version 2: numpy int types aren't promoted to bigger types.
New in numpy version 2: numpy int types aren't promoted to bigger types.
>>> np.uint8(1) + 255
>>> np.uint8(1) + 255
<python-input-21>:1: RuntimeWarning: overflow encountered in scalar add
<python-input-21>:1: RuntimeWarning: overflow encountered in scalar add
np.uint8(0)
np.uint8(0)
#

>>> np.__version__
>>> np.__version__
'2.2.4'
'2.2.4'




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


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

Revision as of 15:54, 11 December 2025

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'