[英]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.