The Numpy version of modulo uses a different sign convention for negative arguments than does Python itself:
-5 % 3 1 array((-5,-5)) % 3 array([-2, -2])
(Numpy version 20.2.0, Python version 1.5.2 and version 2.2a4.) Is there a reason for this (hard to imagine), or is this a bug? Eric
On Fri, 12 Oct 2001, Eric Nodwell wrote:
The Numpy version of modulo uses a different sign convention for negative arguments than does Python itself: ... Is there a reason for this (hard to imagine), or is this a bug?
Numpy delegates to the C platform's / and % operators, Python does it "right". Maybe this should go on the FAQ. Waren Focke
On Fri, 12 Oct 2001, Eric Nodwell wrote:
Numpy delegates to the C platform's / and % operators, Python does it "right". Wouldn't it be preferable to change Numpy so it is also "right"?
Speed. In Python, there's so much overhead from symbol resolution, looking up __mod__s and __rmod__s and whatnot that the extra work is lost in the noise. Numpy would take a bigger hit when working with large arrays. One could always write python_compatible_div and python_compatible_mod functions, if one wanted. Could even submit a patch to add them, if truly motivated. Warren Focke
participants (2)
-
Eric Nodwell
-
Warren Focke