samedi 4 novembre 2017

Partial random selection of items from numpy array from items that meet certain condition

I have a bool array that was created with respect to a double array:

array1 = ... # the double array initialization
array2 = array1 < threshold # threshold is set somewhere else

Assuming the output of my second array is like this:

# array2 = [True, False, True, True, True, False]

I want to select percentage of the True items. For example, if I want to randomly select 75% of the True items, the output would be any of these:

# array3 = [True, False, True, True, False, False]
# array3 = [False, False, True, True, True, False]
# array3 = [True, False, False, True, True, False]

The third array contains 3 out of the 4 True items that were found in the second array. How can I achieve this?




Aucun commentaire:

Enregistrer un commentaire