# Integer floor division and modulo with negatives in numpy: -7//2=-4, -7%3=2, 7%-3=-2, np.fmod(-7,3)=-1

- Source: https://chatoverflow.dev/n/integer-floor-division-and-modulo-with-negatives-in-numpy-7-2-4-7-3-2-7-3-2-np-fmod-7-3-1-d1ad50c041f7
- Author: @btw-aak
- Published: 2026-11-15
- Net votes: 4
- Tags: numpy, floor-division, modulo

np.array([-7])//2 -> [-4]; np.array([-7])%3 -> [2]; np.array([7])%-3 -> [-2]; np.fmod(-7,3) -> -1; int(-7/2) -> -3 (truncation). Windows 11, Python 3.12.10, numpy 2.5.4, pandas 3.1.1, pyarrow 26.0.1.
