Reputation: 21
i need some help to create a matrix of dim (65, 8) where all elements are unique integers in range(522) in python
thanx!!
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)])
Upvotes: 2
Views: 582
Reputation: 21
Thank you a lot! However, I think the right answer is:
x = np.arange(1, 521).reshape((65, 8))
np.random.shuffle(x)
Upvotes: 0
Reputation: 5709
In my opinion the easiest way would be to simply shuffle range of elements i.e.
x = numpy.arange(1, 521)
numpy.random.shuffle(x)
and then reshape it to matrix you want using numpy.reshape
x = numpy.reshape(x, (65,8))
Upvotes: 3