无放回抽样(Sampling without replacement)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无放回抽样(Sampling without replacement)相关的知识,希望对你有一定的参考价值。
import sys
import random
import stdarray
import stdio
m = int(sys.argv[1])
n = int(sys.argv[2])
# Initialize array perm = [0,1,...,n-1]
perm = stdarray.create1D(n, 0)
for i in range(n):
perm[i] = i
# Create a random sample of size m in perm[0,..m)
for i in range(m):
r = random.randrange(i, n)
# Exchange perm[i] and perm[r].
temp = perm[r]
perm[r] = perm[i]
perm[i] = temp
# Write the results.
for i in range(m):
stdio.write(str(perm[i]) + ‘ ‘)
stdio.writeln()
以上是关于无放回抽样(Sampling without replacement)的主要内容,如果未能解决你的问题,请参考以下文章