I have some data currently stored in 3 lists, let's call them a
, b
and c
. The lists all contain n
elements. I would like to take a random sample of my data, say of size sample_n
, to create some smaller dataset to play around with but I want to take the same random sample from each list. That is, I want to randomly select the same elements from each list. So if I randomly select element i
, I would like to take element i
from each list (a[i]
, b[i]
and c[i]
). I do not want to generate 3 sets of random numbers so that the three lists' elements do not match. E.g.running this random sampling for each set separately is not what I want.
I would think all I need to do is generate a separate list of random numbers, random_list
, that is of length sample_n
and then do something like
for element in range(len(random_list)):
sample_a[element] = a[random_list[element]]
sample_b[element] = b[random_list[element]]
sample_c[element] = c[random_list[element]]
However, I don't know how to generate a random number list! And also I was wondering if there was a more efficient method than what i was thinking of here.
Aucun commentaire:
Enregistrer un commentaire