Python Forum
numpy help: Uniform order-based crossover
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
numpy help: Uniform order-based crossover
#1
Hello,
I have two array A & B as follow,
A = [2,6,4,5,3,1]
B = [1,4,3,6,5,2]
From which I formed a numpy array;
oldArr = np.array([[2,6,4,5,3,1],[1,4,3,6,5,2]])
Then I must randomly pick (e.g) 3 columns, lets say;
idx = np.random.randint(len(oldArr[0]), size = len(oldArr[0])/2)

This give the index of the random numbers;
array([3, 4, 0])
and the corresponding values are;
[[5 3 2]
[6 5 1]]
Now I want to construct a new array as such: I must keep those random numbers in the same position and swap 0th raw and the 1st raw in such a way that numbers should not repeat in the new array and must put the non-repeating number in the same order.
before;
[2,_,_,5,3,_]
[1,_,_,6,5,_]
After swapping in my case it must be like this (we can see the numbers are unique in the raws);
[2,1,4,5,3,6]
[1,2,4,6,5,3]
Could anyone help me with this?
Thank you.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020