[SciPy-User] weired results with ode solver

Rob Clewley rob.clewley at gmail.com
Sat Feb 6 14:30:49 EST 2010


Hi,

> The behavior of array int devision is a bit funny, but after you get
> used to it, it's fine.

You can always use

from __future__ import division

at the top of all your files and you'll be safe to do this division
(at an almost negligible performance hit). The mathematically
intuitive version of division is standard in Python 3000.

>>>> timerange=arange(1,12)
>>>> timerange/2
> array([0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5]) #this is why i got multiple values
>>>> timerange/2.0
> array([ 0.5,  1. ,  1.5,  2. ,  2.5,  3. ,  3.5,  4. ,  4.5,  5. ,  5.5])

You may wish to check out numpy's linspace command for generating
float arrays with arbitrary step sizes in a numerically safe manner
(and with endpoints included by default).

-Rob



More information about the SciPy-User mailing list