1

I'm trying to inter-change columns from 2 matrices, but my assignment seems to not be doing it.

crom1 = crossover_list[0][0][:,j]
print('c1', crom1)
crom2 = crossover_list[1][0][:,j]
print('c2', crom2)

crossover_list[0][0][:,j] = crom2

print(crossover_list[1][0][:,j])
crossover_list[1][0][:,j] = crom1
print(crossover_list[1][0][:,j])

And this is what comes out: enter image description here

Any suggestions?

LE: I also tried the following, with no success:

aux = crossover_list[0][0][:,j]
crossover_list[0][0][:,j] = crossover_list[1][0][:,j]
crossover_list[1][0][:,j] = aux
Silviu Tofan
  • 379
  • 1
  • 3
  • 17

1 Answers1

1
aux = numpy.copy(crossover_list[0][0][:,j])
crossover_list[0][0][:,j] = crossover_list[1][0][:,j]
crossover_list[1][0][:,j] = aux

Seems to work like this (based on Swapping columns in a numpy array? )

Community
  • 1
  • 1
Silviu Tofan
  • 379
  • 1
  • 3
  • 17
  • Your code and question would be simpler if you used `x=crossover_list[0][0]`, and `y=crossover_list[1][0]`, and made sure they were both `ndarray` (as opposed to lists or list of lists). – hpaulj Jun 27 '16 at 04:07
  • Unfortunately I don't think I can do that, as I'm switching columns between 2 matrices, but not all the columns. – Silviu Tofan Jun 27 '16 at 12:55