ValueError: Sample larger than population or is negative

简介: 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
相关文章
|
8月前
|
Linux Windows
【已解决】ValueError: num_samples should be a positive integer value, but got num_samples=0
【已解决】ValueError: num_samples should be a positive integer value, but got num_samples=0
|
8月前
random.sample(population, k)
random.sample(population, k)
44 0
|
JSON 数据格式
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
545 0
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be
成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be
成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be
|
Linux Python
ValueError: empty range for randrange() (0, 0, 0)
ValueError: empty range for randrange() (0, 0, 0)
|
数据库
Incorrect result size: expected 1, actual 2
Incorrect result size: expected 1, actual 2
926 0
ValueError: Sample larger than population or is negative
ValueError: Sample larger than population or is negative
407 0
|
索引 Python
成功解决ValueError: Shape of passed values is (33, 1), indices imply (33, 2)
成功解决ValueError: Shape of passed values is (33, 1), indices imply (33, 2)
|
计算机视觉 索引
成功解决ValueError: Shape of passed values is (1, 332), indices imply (1, 1)
成功解决ValueError: Shape of passed values is (1, 332), indices imply (1, 1)