mercredi 19 septembre 2018

Python: Generate matrix having random 1 or 0, ensuring every row/ column has at least a single '1'

I am generating 2D array with random 1 and 0 using numpy.random.randint(0,2,(4,5)) (for the scenario User-Item rating matrix having a value 1 if user likes an item, 0 otherwise). For this scenario, the constraint is that there should be atleast one 1 in every column/ row (can't have all zeros in a col/ row). Is there anything in numpy/ python, which can directly help achieve this.




Aucun commentaire:

Enregistrer un commentaire