#### range() with float step argument [duplicate]

Python十进制范围（）步长值

``````[0, 0.05, 0.1, 0.15 ... ]
``````

range（）整数步骤参数预期，得到浮点数。

5 个回复

``````>>> 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.  ])
``````

``````def frange(start,stop, step=1.0):
while start < stop:
yield start
start +=step
``````

``````for x in frange(0, 1, 0.05):
print(x)
``````

Python不需要太棘手。

``````list(frange(0,1,0.05))
``````

``````[v*0.05 for v in range(0,int(1/0.05))]
``````

``````temp = range(0,100,5) # 0,5,10,...,95
final_list = map(lambda x: x/100.0,temp) # becomes 0,0.05,0.10,...,0.95
``````

``````[i/100.0 for i in range(0, 100, 5)]
``````

1 具有float类型的步骤的范围[duplicate]

2010-11-15 23:09:27 8 111944   range
2 Python-将一个float范围（不带任何步长）作为函数的参数传递

3 浮动步的标量范围精度

2016-11-15 10:24:40 5 1536   scala
5 Python十进制range（）逐步值[重复]

2016-01-02 03:33:55 1 188   python
6 返回函数值到范围参数步骤

2012-03-31 19:08:20 3 356   range
7 如何在离子范围内保留浮点数

2017-06-13 11:34:46 1 1034   ionic3
8 将步长取决于范围将整数值转换为浮点值

2018-10-29 00:34:08 2 66   math
9 ArgumentOutOfRangeException：参数超出范围[重复]