ValueError: Sample larger than population or is negative

选取样本函数random.sample

正确使用示例

# -*- coding: utf-8 -*-

import random

lst = [1, 2, 3]
ret = random.sample(lst, 2)
print(ret)
# [3, 2]

如果选取的数量比全量数据多,就会报错

# -*- coding: utf-8 -*-

import random

lst = [1, 2, 3]
ret = random.sample(lst, 4)
print(ret)
# ValueError: Sample larger than population or is negative
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页