python-small-examples

@author jackzhenguo
@desc 
@date 2019/5/1

80 sample 样本抽样

使用sample抽样,如下例子从100个样本中随机抽样10个。

from random import randint,sample
lst = [randint(0,50) for _ in range(100)]
print(lst[:5])# [38, 19, 11, 3, 6]
lst_sample = sample(lst,10)
print(lst_sample) # [33, 40, 35, 49, 24, 15, 48, 29, 37, 24]
[上一个例子](/python-small-examples/md/79.html) [下一个例子](/python-small-examples/md/81.html)