If you can use numpy, it's a good idea to use numpy.linspace
. Functions that try to fit range
logic on floating-point numbers, including numpy's own arange
, usually get confusing regarding whether the end boundary ends up in the list or not. linspace
elegantly resolves that by having you to explicitly specify the start point, the end point, and the desired 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. ])