vendredi 29 mai 2020

How to keep track of row index of the rows I randomly select from a matrix?

I am trying to perform tournament selection in a GA whereby I need select two rows randomly. Is there a way of keeping track of the index values of the 2 random rows I select from the matrix self.population and storing those in variables?

At the moment it just outputs the two random rows but I need to keep track of which rows were selected.

Below is what I have so far although ideally I would like to store both rows I select from my matrix in separate variables.


self.population = [[0 1 1 1 0 0 1 1 0 1]
                  [1 0 1 1 0 0 0 1 1 1]
                  [0 0 0 0 0 1 1 0 0 0]
                  [1 1 0 0 1 1 1 0 1 1]
                  [0 1 0 1 1 1 1 1 1 0]
                  [0 0 0 0 1 0 1 1 1 0]]

def tournament_select(self):
    b = np.random.randint(0, self.population[0], 2) 
    return self.population[b]




Aucun commentaire:

Enregistrer un commentaire