+ 1
[SOLVED] Is there a way to generate a float range list with step ?
I would like to know a way to generate a list like range(0,10) with float example range(pi,2pi,0.01)
3 ответов
+ 14
# You can use numpy arange() for that. It works similarly to range with (start, stop, step). Just the code below and run it to see:
import numpy as np
print(np.arange(np.pi, 2*np.pi, 0.1))
+ 4
Although, IMO, numpy is the way to go, you could also use simple list comprehension with some basic math to accomplish this.
from math import pi
lst = [x * 0.01 + pi for x in range(1, 101)]
lst = [pi]+lst
print(lst)