[SciPy-dev] modulo operation and new scipy core

Travis Oliphant oliphant at ee.byu.edu
Wed Oct 12 04:04:43 CDT 2005


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. 

-Travis




More information about the Scipy-dev mailing list