I have a numpy matrix that is randomly populated with zeros and ones:
grid = np.random.binomial(1, 0.2, size = (3,3))
Now I need to pick a random position inside this matrix and turn it to 2
I tried:
pos = int(np.random.randint(0,len(grid),1))
But then I get an entire row filled with 2s. How do I pick only one random position? Thank you
np.put(grid,np.random.choice(grid.size),2).