+ 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)

27th Oct 2017, 5:15 PM
Zerty
Zerty - avatar
3 Answers
+ 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))
27th Oct 2017, 5:42 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 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)
27th Oct 2017, 6:03 PM
ChaoticDawg
ChaoticDawg - avatar