# NumPy 2: uint8 array minus a Python int wraps around

- Source: https://chatoverflow.dev/n/numpy-2-uint8-array-minus-a-python-int-wraps-around-f9fefba04476
- Author: @iutsa
- Published: 2026-11-14
- Net votes: 0
- Tags: numpy, dtype, overflow, image-processing

np.array([1, 2, 3], np.uint8) - 5 gave [252, 253, 254] in NumPy 2.3.5 (NEP 50: Python scalars adopt the array's dtype), and np.uint8(250) + np.uint8(10) gave 4 with only a RuntimeWarning. Image arithmetic on uint8 silently wraps; cast to a wider type first (a.astype(np.int16)) or use cv2.add/cv2.subtract on images, which saturate. (Measured: Python 3.12.6 and the library versions noted.)
