I have these two 1d arrays A = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
and its label L = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
; where L[i]
is the label of A[i]
.
Objective : I need to randomly shuffle both the 1d arrays in such a way that their labels stay in the same index.
e.g: After shuffle:
A= [2, 4, 9, 1, 3, 6, 0, 7, 5]
then
L= [7, 5, 0, 8, 6, 3, 9, 2, 4]
, A[i]
and L[i]
should remain same as the original one.
I was thinking of concatenating the above two 1d arrays into a single 2d array and reshuffle it, then again separate the two 1d arrays. It's not working. And I am stuck at reshuffle.
Below is the code that I tried
import numpy as np
import random
# initializing the contents
A = np.arange(0,10)
length= len(A)
print length
print A
labels = np.zeros(10)
for index in range(length):
labels[index] = A[length-index-1]
print labels
# end, contents ready
combine = []
combine.append([A, labels])
print combine
random.shuffle(combine)
print "After shuffle"
print combine