1

I have a given sample distribution like for example [1,2,3,4,6,10]. From this I would like to get a random list of samples where the values come from the initial samples. So basically I want the same samples just in a random order (so the number of samples in the random sample set remains the same). I can do this using random.sample() but I am not sure how random this really is.

Is there a similar functionality in numpy that I can use for scientific purpose?

1
  • 3
    Aren't you just shuffling list elements? shuffle()? Commented Apr 8, 2015 at 13:43

1 Answer 1

2

You can use random.shuffle :

>>> import random
>>> a=[1,2,3,4,6,10]
>>> random.shuffle(a)
>>> a
[1, 3, 6, 2, 10, 4]

And same in numpy with numpy.random.shuffle:

>>> import numpy as np
>>> np.random.shuffle(a)
>>> a
[4, 6, 10, 3, 1, 2]
Sign up to request clarification or add additional context in comments.

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.