0

I want to shuffle the rows of my matrices. Here is my code:

               #prepare the training data
dat_training = data_all_training[sbj]
                
                
labels_training = dat_training.select("Label")
labels_test = dat_test.select("Label")
                

                
y_w2v_train_n = return_normal_features_for_MEG_training(labels_training, type_emb)
y_w2v_pt_n = return_normal_features_for_MEG_validation(labels_test, type_emb)
                
y_w2v_train_s = y_w2v_train_n
y_w2v_pt_s = y_w2v_pt_n

  
np.random.shuffle(y_w2v_train_s)
np.random.shuffle(y_w2v_pt_s)

print("sim", y_w2v_train_s[0,0:10] == y_w2v_train_n[0, 0:10])
print(y_w2v_train_s[0, 0:10])
print(y_w2v_train_n[0, 0:10])
print("shapes", x_train.shape, y_w2v_train.shape, x_test_pt.shape, y_w2v_pt.shape)
 

Result is:

sim [ True  True  True  True  True  True  True  True  True  True]
[ 0.12567943  0.38765216  0.05903614  0.35545474  0.15695235 -0.09684472
  0.20318605  0.09171303  0.19060805  0.19470002]
[ 0.12567943  0.38765216  0.05903614  0.35545474  0.15695235 -0.09684472
  0.20318605  0.09171303  0.19060805  0.19470002]
shapes (7200, 99) (7200, 1000) (300, 99) (300, 1000)

How can I fix it? Where is wrong?

Kadaj13
  • 1,423
  • 3
  • 17
  • 41
  • `y_w2v_train_s = y_w2v_train_n` does not make a copy: you just get a reference to the same array. – trincot Jun 02 '23 at 05:55
  • @trincot thank you very much. So how should I fix it. I want to have the original array and a shuffled one – Kadaj13 Jun 02 '23 at 05:56
  • It looks like you use numpy, so then it is `y_w2v_train_s = numpy.copy(y_w2v_train_n)` -- the next statement needs the same change. – trincot Jun 02 '23 at 06:01

0 Answers0