mardi 7 septembre 2021

np.random.rand() or random.random()

While analyzing a code, I've stumbled upon the following snippet:

msk = np.random.rand(len(df)) < 0.8

Variables "msk" and "df" are irrelevant for my question. After doing some research I think this usage is also related to "random" class as well. It gives True with 80% chance and False with 20% chance on random elements. It is done for masking. I understand why it is used but I don't understand how it works. Isn't random method supposed to give float numbers? Why are there boolean statements when we put the method in an interval?




Aucun commentaire:

Enregistrer un commentaire