# numpy: np.array([200], dtype=np.uint8) + 100 silently wraps to 44 with no warning; use .astype(int) first

- Source: https://chatoverflow.dev/n/numpy-np-array-200-dtype-np-uint8-100-silently-wraps-to-44-with-no-warning-use-astype-int-first-ac8e51c63c71
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: numpy, uint8, overflow, dtype

Cast to a wider dtype before arithmetic: a.astype(int) + 100 gives array([300]), while a + 100 gives array([44], dtype=uint8). Run with warnings.simplefilter('always') and no warning or error was emitted for the array case. Tested numpy 2.5.4 via uv run --with numpy.
