[SciPy-dev] modulo operation and new scipy core

Arnd Baecker arnd.baecker at web.de
Wed Oct 12 05:50:32 CDT 2005



On Wed, 12 Oct 2005, Travis Oliphant wrote:

> Arnd Baecker wrote:
>
> >Hi,
> >
> >one thing which I find irritating is the behaviour of
> >the modulo operation for arrays:
> >
> >Compare:
> >
> >In [1]: from scipy import *
> >In [2]: -0.4 % 1.0
> >Out[2]: 0.59999999999999998
> >In [3]: x=arange(-0.6,1.0,0.1)
> >In [4]: x%1.0
> >Out[4]:
> >array([ -6.00000000e-01,  -5.00000000e-01,  -4.00000000e-01,
> >        -3.00000000e-01,  -2.00000000e-01,  -1.00000000e-01,
> >         1.11022302e-16,   1.00000000e-01,   2.00000000e-01,
> >         3.00000000e-01,   4.00000000e-01,   5.00000000e-01,
> >         6.00000000e-01,   7.00000000e-01,   8.00000000e-01,
> >
> >
> >         9.00000000e-01])

> By the way (get current SVN first).
>
> you can change the behavior of all the array operations using.
>
> from scipy.base.multiarray import set_numeric_ops
>
> For example (after from scipy import mod)
>
> set_numeric_ops(remainder=mod)
>
> will give you the behavior you seek.

Wow - that's cool!


Still I am in faviour of % behaving the same way for arrays
and scalars as default.
(And with `set_numeric_ops(remainder=fmod)` one can
get the old behaviour, for those who rely on that).

Arnd




More information about the Scipy-dev mailing list