jeudi 22 avril 2021

Random permutation/shuffle but guarantees to change every element

I have a np.ndarray, and I want to use shuffle/permutation, but I also want to make sure that every element position is changed. For example:

>>> arr = [1, 2, 3]
>>> np.random.shuffle(arr)
>>> print(arr)
[1, 3, 2]  # One possible output

Desired output: [3, 2, 1], or any permutation that every element position is changed



Aucun commentaire:

Enregistrer un commentaire