I wanted to quickly grab a random sample of values from a larger array to perform
some testing. I didn’t need to worry about the distribution of the sampled data: I just
needed n
values drawn at random from the array. I used shuffle
from numpy.random
to randomise the values in my input array. shuffle
operates in place, so I made a
copy of the array to avoid future problems. I can then simply take a slice of the
first n
values in the array, which will be a random selection of n
values drawn from
the original data:
This can be tested using some example data:
Which yields: