If you can use numpy, numpy.linspace recommended. Functions that try to accommodate range logic in floating point numbers, including numpy own arange , are usually confused as to whether the ending border in the list ends or not. linspace elegantly decides that if you explicitly specify a start point, an end point, and the required number of elements:
>>> import numpy >>> numpy.linspace(0.0, 1.0, 21) array([ 0. , 0.05, 0.1 , 0.15, 0.2 , 0.25, 0.3 , 0.35, 0.4 , 0.45, 0.5 , 0.55, 0.6 , 0.65, 0.7 , 0.75, 0.8 , 0.85, 0.9 , 0.95, 1. ])
source share