比如我有一个list,怎么对这个list进行有放回的随机抽样?
谢谢!
2个回答
numpy.random.choice
import numpy as np
>> a = [1, 3, 5]
>> np.random.choice(a, size=10, replace=True)
array([3, 3, 5, 5, 5, 1, 3, 3, 1, 5])
>>> from random import choices
>>> colors = ["R", "G", "B"]
>>> choices(colors, k=4)
['G', 'R', 'G', 'B']