python - numpy.arange divide by zero errror -
i have used numpy's arange funciton make following range:
a = n.arange(0,5,1/2)
this variable works fine itself, when try putting anywhere in script error says
zerodivisionerror: division 0
first, step
evaluates 0 (on python 2.x is). second, may want check np.linspace
if want use non-integer step.
docstring: arange([start,] stop[, step,], dtype=none) return evenly spaced values within given interval. [...] when using non-integer step, such 0.1, results not consistent. better use ``linspace`` these cases.
in [1]: import numpy np in [2]: 1/2 out[2]: 0 in [3]: 1/2. out[3]: 0.5 in [4]: np.arange(0, 5, 1/2.) # use float out[4]: array([ 0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4.5])
Comments
Post a Comment