python中怎么对list中元素进行有放回抽样?
1个回答
numpy.random.choice
import numpy as np
a = ['u', 'v', 'w', 'x', 'y', 'z']
# 有放回抽样
sample_wt = np.random.choice(a, 5, replace=True)
print(sample_wt)
# 无放回抽样
sample_wo = np.random.choice(a, 5, replace=False)
print(sample_wo)
SofaSofa数据科学社区DS面试题库 DS面经
谢谢!
-
vanderwaals
2019-05-09 13:54