sample 这个函数怎么用啊?
sample 这个函数,样本,怎么用啊?在哪可以查到用法? >>> import random>>> help(random.sample)
Help on method sample in module random:
sample(population, k) method of random.Random instance
Chooses k unique random elements from a population sequence or set.
Returns a new list containing elements from the population while
leaving the original population unchanged.The resulting list is
in selection order so that all sub-slices will also be valid random
samples.This allows raffle winners (the sample) to be partitioned
into grand prize and second place winners (the subslices).
Members of the population need not be hashable or unique.If the
population contains repeats, then each occurrence is a possible
selection in the sample.
To choose a sample in a range of integers, use range as an argument.
This is especially fast and space efficient for sampling from a
large population: sample(range(10000000), 60)
>>> 本帖最后由 z5560636 于 2021-3-28 20:18 编辑
语法
random.sample(sequence, k)
参数
参数 必需的 描述
sequence 是 一个序列。 可以是任何序列:列表,集合,范围等。
k 是 返回列表的大小
z5560636 发表于 2021-3-28 20:16
语法
random.sample(sequence, k)
谢谢啊
页:
[1]