How to effectively shuffle a numpy array in pieces

I have a numpy array that looks like this: [-1,0,1,0,1,2,1,2,3, ..., n-1, n, n + 1, n, n + 1 , N + 2 ..] I would like to shuffle the array in pieces 3, is there an efficient way to do this in numpy?

I know that you can shuffle a numpy array using the following shuffle method, but this gives me a fully shuffled array. Is there any way to shuffle it in pieces in numpy?

import numpy.random as rng ind = numpy.arange(100) rng = numpy.random.RandomState(123) rng.shuffle(ind) 
+1
source share
1 answer

Change to 3 columns. shuffle doc says that it just moves the 1st dimension:

 ind=np.arange(99) # multple of 3 ind=ind.reshape(-1,3) rng.shuffle(ind) ind.flatten() 
+5
source

Source: https://habr.com/ru/post/1272158/


All Articles