|
例子:
#python中的range函数支持步进,如下:
>>> print range(2,15,3)
[2, 5, 8, 11, 14]
#但是浮点数不支持range函数,自己定义一个类似的
from decimal import *
def floatrange(start,stop,steps):
'''
start:计数从 start 开始
stop:计数到 stop 结束
step:步长
'''
resultList = []
while Decimal(str(start)) <= Decimal(str(stop)):
resultList.append(float(Decimal(str(start))))
start = Decimal(str(start))+Decimal(str(steps))
return resultList
alleleFreqeuncy = floatrange(0.5,0.95,0.05)
返回:
print(alleleFreqeuncy)
[0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95]
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-9-28 05:21
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社