lundi 4 juillet 2022

Random position from a boolean array

I have a 2D boolean array, and I want to generate one random location where it's 1.

array([[0, 0, 0, 1, 1, 1, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1],
       [0, 0, 1, 1, 1, 1, 1, 1],
       [0, 1, 1, 1, 0, 0, 0, 1],
       [0, 1, 1, 1, 0, 0, 1, 1]])

Example output:

(2,2)



Aucun commentaire:

Enregistrer un commentaire