2

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)])
5
  • Why it should be from range 0 to 521? This matrix should have exactly 520 elements. So do you want two of them to be missing? Commented Dec 15, 2017 at 8:47
  • no, you are right i want 520 elements.. Commented Dec 15, 2017 at 8:49
  • Including 0? So do you want numbers from range 0..519 or 1..520? Commented Dec 15, 2017 at 8:51
  • i want 1 to 520 Commented Dec 15, 2017 at 8:53
  • 1
    x = np.arange(1, 521), np.random.shuffle(x); x = x.reshape(65, 8) Commented Dec 15, 2017 at 8:55

2 Answers 2

3

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))
Sign up to request clarification or add additional context in comments.

2 Comments

You can do this with numpy's methods, they should be faster.
@cᴏʟᴅsᴘᴇᴇᴅ: Right. Edited:)
0

Thank you a lot! However, I think the right answer is:

x = np.arange(1, 521).reshape((65, 8))
np.random.shuffle(x)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.