0

I have an array with the shape of TxCxHxW, how can I change the order inside a channel.

For example, I have a and like to change it so I get b as following (please note that it is just an example, in general, I am looking for a way fast to change the order inside the channel, The change of order is not random and we always have the pattern):

a = np.arange(48).reshape(4,3,2,2)
b = np.zeros_like(a)
b[0,:,:,:] =a[1,:,:,:]
b[1,:,:,:] =a[3,:,:,:]
b[2,:,:,:] =a[0,:,:,:]
b[3,:,:,:] =a[2,:,:,:]
Alex
  • 1,091
  • 12
  • 19
  • How do you want to change the order though. If you want to randomly shuffle, you could use `np.random.shuffle` or other way would be to create a 1-D np array of indices and just do `b = a[required_indices_arr]`. – Anurag Reddy Aug 21 '20 at 15:30
  • it is not random, I always have a pattern. can you say how you can do it for my example. – Alex Aug 21 '20 at 15:43
  • So, what's **the pattern** for a generic case with n elements? – Divakar Aug 21 '20 at 15:44
  • let say the pattern is what I showed in the example – Alex Aug 21 '20 at 15:45

1 Answers1

2

To get the same result as your code, you can do something like:

a = np.arange(48).reshape(4,3,2,2)
b = a[[1,3,0,2], :, :]
Bas
  • 143
  • 5