Is there a way to step between 0 and 1 by 0.1?
I thought I could do it like the following, but it failed:
for i in range(0, 1, 0.1):
print i
Instead, it says that the step argument cannot be zero, which I did not expect.
Is there a way to step between 0 and 1 by 0.1?
I thought I could do it like the following, but it failed:
for i in range(0, 1, 0.1):
print i
Instead, it says that the step argument cannot be zero, which I did not expect.
NumPy is a bit overkill, I think.
Generally speaking, to do a step-by-
1/x
up toy
you would do(
1/x
produced less rounding noise when I tested).My answer is similar to others using map(), without need of NumPy, and without using lambda (though you could). To get a list of float values from 0.0 to t_max in steps of dt:
My solution:
scipy
has a built in functionarange
which generalizes Python'srange()
constructor to satisfy your requirement of float handling.from scipy import arange
Building on 'xrange([start], stop[, step])', you can define a generator that accepts and produces any type you choose (stick to types supporting
+
and<
):