mardi 2 mars 2021

Shuffle array by group in python

Let's assume I have two arrays:

values = [1,2,3,4,5,6,7,8,9]
groups = [0,0,0,1,1,2,2,3,4]

Is it possible to shuffle "values" only within groups? E.g. elements in group 0 (1,2,3) are going to be shuffled only with each other, elements in group 1 (4,5) are going to be shuffled with each other and so on.

I have huge numpy arrays, is there any efficient way to do so?




Aucun commentaire:

Enregistrer un commentaire