jeudi 17 août 2017

Choose random elements from specific elements of an array

I have a 1D (numpy) array with boolean values. for example:

x = [True, True, False, False, False, True, False, True, True, True, False, True, True, False]

The array contains 8 True values. I would like to choose, for example, 3 (must be less than 8 in this case) random elements out of the 8 that exist and get as an output an array with the same length as x with Trues at 3 random places. A possible result can be:

x = [True, True, False, False, False, False, False, False, False, False, False, False, True, False]

How to implement it?




Aucun commentaire:

Enregistrer un commentaire