[MATRIX-SIG] Inconsistent mod behaviour

Konrad Hinsen hinsen@ibs.ibs.fr
Tue, 3 Mar 1998 10:41:20 +0100

A colleague made me aware of an inconsistency in the modulo operation
for arrays and scalars:

>>> from Numeric import *
>>> -15%2
>>> array([-15])%2

Some further investigation shows that this is the result of different
truncation rules for integer division, i.e. division and modulo are
consistent in both cases:

>>> -15/2
>>> array(-15)/2

Nevertheless, it is an annoying problem. However, it was not really
introduced by NumPy. NumPy uses fmod() and therefore inherits its
documented behaviour. The same is true for math.fmod and Numeric.fmod.

I am not sure what to do about this. It seems reasonable to let arrays
behave like scalars for consistency, but of course leave the explicit
function fmod() as it is. Does anyone see a problem with that solution?

Konrad Hinsen                          | E-Mail: hinsen@ibs.ibs.fr
Laboratoire de Dynamique Moleculaire   | Tel.: +33-
Institut de Biologie Structurale       | Fax:  +33-
41, av. des Martyrs                    | Deutsch/Esperanto/English/
38027 Grenoble Cedex 1, France         | Nederlands/Francais

MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org