I need to find a random element in a 2D array, as the title says.Then i need to perform an operation on this.
For example:
Grid = np.zeros((64,64))
ones = np.ones((32,64))
minus = -1 * ones
Grid[0:32,:] = ones[:]
Grid[32:64,:] = minus[:]
So its half full of 1's,half of -1's.Then i need select a random element of this 2D array,and perform an operation on it. For example it needs to do something like:
def change(Grid):
Grid[0,0] *= -1
But for a random element inside this list,but obviously the below code doesn't work.
Grid[random.choice,random.choice] *= -1
Is there a way to do this with random.choice,or is there another way to make this work?
Aucun commentaire:
Enregistrer un commentaire