-
Notifications
You must be signed in to change notification settings - Fork 177
工具函数
Toto Lin edited this page May 18, 2017
·
1 revision
CYaRon 提供了一些简单的工具函数。
ati(array)
ati函数输入一个数组,将数组的每一个元素转换为整形数后返回。
因为Python的1E5此类表达式返回的是浮点值,因此使用这类表达式定义数据范围时,需要通过此函数处理数组。
_n = ati([0, 5, 100, 1E3, 1E5])randint(n, m)
为标准库random.randint的别名。randint接受两个参数,生成[n, m]范围内(既,包含n和m)的随机整数。
randint(1, 5) # int in [1, 5]randrange([n,] m [,step])
为标准库random.randrange的别名。请查看Python文档获得更多信息。
uniform(n, m)
为标准库random.uniform的别名。uniform接受两个参数,生成[n, m]范围内(既,包含n和m)的随机浮点数。
uniform(1, 5) # float in [1, 5]choice(seq)
为标准库random.choice的别名。choice从给定的数组中随机选取一个值返回。
choice([1, 2, 3])random()
为标准库random.random的别名。random返回[0, 1)范围内(既,包含0但不包含1)的随机浮点数。
random() # float in [0, 1)文档
高级使用
贡献相关