I have a numpy array as follows.
data = np.array([True, True, True, True, False, True, True, False, True, True, False])
From the locations of 'True', I have to randomly sample 3 locations and keep them as True, besides them, convert as False.
I tried as:
indx = np.random.choice(len(data),3,replace=False)
data[~indx] = False
How to do it in a better (1. easy, 2. performance, 3. elegance)?
print (data)
Also, how to sample only from 'True` locations? My code is doing from all locations and incorrect.