Function range(stop) | range(start, stop[, step]) range(stop) | range(start, stop[, step]) returns a sequence of numbers, starting from the lower bound to the upper bound with the specified step. And the parameters must be integers.

How to create a range of float values? something like frange(0, 1.5, 0.1)

    1 answer 1

     In [40]: import numpy as np In [41]: np.arange(0, 1.5, 0.1) Out[41]: array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. , 1.1, 1.2, 1.3, 1.4]) 

    if there are boundaries of the range (both ends must belong to the range) and the number of points needed:

     In [46]: np.linspace(0, 1.4, 15) Out[46]: array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. , 1.1, 1.2, 1.3, 1.4]) 

    without numpy:

     In [42]: [x/10 for x in range(15)] Out[42]: [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4]