Skip to content

Instantly share code, notes, and snippets.

@gsurma
Created December 23, 2018 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsurma/32159752f76484a3c1739a18647a0e04 to your computer and use it in GitHub Desktop.
Save gsurma/32159752f76484a3c1739a18647a0e04 to your computer and use it in GitHub Desktop.
def _crossover(self, x, y):
offspring_x = x
offspring_y = y
for a in range(0, len(offspring_x)): # 10
a_layer = offspring_x[a]
for b in range(0, len(a_layer)): # 8
b_layer = a_layer[b]
if not isinstance(b_layer, np.ndarray):
if random.choice([True, False]):
offspring_x[a][b] = y[a][b]
offspring_y[a][b] = x[a][b]
continue
for c in range(0, len(b_layer)): # 8
c_layer = b_layer[c]
if not isinstance(c_layer, np.ndarray):
if random.choice([True, False]):
offspring_x[a][b][c] = y[a][b][c]
offspring_y[a][b][c] = x[a][b][c]
continue
for d in range(0, len(c_layer)): # 4
d_layer = c_layer[d]
for e in range(0, len(d_layer)): # 32
if random.choice([True, False]):
offspring_x[a][b][c][d][e] = y[a][b][c][d][e]
offspring_y[a][b][c][d][e] = x[a][b][c][d][e]
return offspring_x, offspring_y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment