I'm trying to swap elements between two lists, and python doesn't seem to let that happen.
def swap(A,B,i,j):
TEMP_B = B[j]
B[j] = A[i]
A[i] = TEMP_B
return A,B
X = np.array([[1.25,3],[1.5,2],[2,2.75],[2.25,2],[2,0.5],[3.25,0.75],
[3.5,2.25],[4.25,0.75]])
Y = np.array([[2.75,3.5],[3.25,3],[4.5,2.75],[3.5,4.75]])
X,Y = swap(X,Y,1,1)
OUTPUT:::
Temp = [ 3.25 3. ]
before swap
X[ 1 ]: [ 1.5 2. ]
Y[ 1 ]: [ 3.25 3. ]
Temp = [ 1.5 2. ]
after swap
X[ 1 ]: [ 1.5 2. ]
Y[ 1 ]: [ 1.5 2. ]
I expect B[j] = old A[i] and A[i] = old B[j] However, only one of the items gets swapped.. Not sure what the problem is. This is the output it get:
I'm expecting X[1] = [3.25,3] but it comes out as [1.5,2]