1

I have a 2000 numpy arrays of size 7 x 11. The rows are arranged in the following order of variables: pi, Tajima's D, Theta, dust kurtosis, J1/J2, J1, J2. That is first row always corresponds to pi, second row corresponds to Tajima's D and so on.

What I want to do is shuffle the rows but also keeping track of in which row has that variable moved to. For example, Tajima's D, Theta, pi, distkurtosis, J1/J2, J1, J2. And I want to keep track that now pi is in row 3. How can I achieve that? Please note, I want to only move the rows and not the columns.

Also, is there a way to make all possible combinations while keeping track of where each variable has move to?

My apologies if it is a really basic question. But, I'm having a hard time finding a solution for this problem.

My code thus far:

def interchange(array, n, m): 
   rows = n 
   #print(array)
   #print('\n')

   # swapping of element
   for i in range(m): 
       t = array[0][i] 

       array[0][i] = array[5][i] 
       array[5][i] = t 

       t = array[4][i]
       array[0][i] = array[8][i]
       array[8][i] = t

   #print(array)
   return array

###Calling the function 
for i in range(2000):
    h1[i] = interchange(h1[i], n, m) 
Shafa Haider
  • 413
  • 2
  • 5
  • 13

1 Answers1

0

keeping track of in which row has that variable moved to

Tack on an original_index column, and give it eleven sequential values according to the original row numbers.

shuffle the rows

Tack on an index column, fill it with random numbers, and sort on that. Choose new random numbers and re-sort if you want to re-shuffle.

Better, choose seed = 0, and fill the index column with sha224(seed, row), so instead of random you have a deterministic function of the row. Increment the seed if you want to re-shuffle.

is there a way to make all possible combinations

Yes, use the permutations() library function to populate the index column. Re-sort on index for each successive permutation.

J_H
  • 17,926
  • 4
  • 24
  • 44
  • Is it possible to give an example. I've made some code. But I have to manually put in the indices. I've edited my code above so you can see my code. I want to reshuffle the rows and then see if my network will still be able to categorise these matrices in the right way. – Shafa Haider Mar 24 '19 at 20:56