mercredi 24 juin 2020

How to randomly choose N items from array and associate them with the right item from another array?

I have two numpy arrays of 4 items each. The i item of the first array is correlated with the i item of the second array, and so on. I need to randomly choose N items from the first array, but I'd like to keep the 'association' with the second one, so that if I pick item #2 from the first array, item #2 of the second one is chosen too.

A sample of the code I'm currently using:

data = np.array([13170.06, 12552.34,  12420.39, 12336.24])
data2 = np.array([6217.69,  12242.05,  9218.21,  5095.23])

choice = data[np.random.choice(len(data), size=1, replace=False)] #In this way I pick 1 item

Basically, if the code samples 13170.06, I need to associate something like choice2 = 6217.69, or in any case to pick the same i-item also from the second array. How can I do it?




Aucun commentaire:

Enregistrer un commentaire