![](/img/trans.png)
[英]How to create a random Matrix in Python without duplicating integers?
[英]how to generate a matrix of random integers without duplicates in python
我需要一些帮助来创建一个dim(65,8)矩阵,其中所有元素都是python中range(522)内的唯一整数
感谢名单!
def bootstrap(x, num_samples, statistic, alpha):
"""Returns bootstrap estimate of 100.0*(1-alpha) CI for statistic."""
n = len(x)
y=len(x)**(1/3)
idx = np.random.randint(0, n, (num_samples, y)) #Return unique random integers from 0 to 520 in a martix with size num_samples X 520.
samples = x[idx]
stat = np.sort(statistic(samples, 1))
return (stat[int((alpha/2.0)*num_samples)],
stat[int((1-alpha/2.0)*num_samples)])
在我看来,最简单的方法是简单地调整元素范围,即
x = numpy.arange(1, 521)
numpy.random.shuffle(x)
然后使用numpy.reshape将其重塑为所需的矩阵
x = numpy.reshape(x, (65,8))
非常感谢! 但是,我认为正确的答案是:
x = np.arange(1, 521).reshape((65, 8))
np.random.shuffle(x)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.