I am trying to do crossover on a Genetic Algorithm population using numpy. I have sliced the population using parent 1 and parent 2.
population = np.random.randint(2, size=(4,8))
p1 = population[::2]
p2 = population[1::2]
But I am not able to figure out any lambda or numpy command to do a multi-point crossover over parents.
The concept is to take ith row of p1
and randomly swap some bits with ith row of p2
.
I think you want to select from p1 and p2 at random, cell by cell.
To make it easier to understand i've changed p1 to be 10 to 15 and p2 to be 20 to 25. p1 and p2 were generated at random in these ranges.
The numbers in the teens come from p1 when sieve is 1 The numbers in the twenties come from p2 when sieve is 0
This may be able to be made more efficient but is this what you expect as output?