vendredi 26 avril 2019

Generate a specific number of ones for each row, but only where x = zeroes

Suppose I have an array like

0 1 1 1 0 0 0 0 1 0

0 0 1 0 0 1 0 0 0 0

1 0 0 0 0 1 0 0 1 0

I want each row to have a specific number of ones- let's say, 5 ones per row. So in the first row I need to add 1 one, second row needs 3 ones, and the third needs 2. I need to randomly generate those ones in places where x = 0.

How do I do this?




Aucun commentaire:

Enregistrer un commentaire