First of all, we need to know a property :pandas Of dataframe or numpy Of array、matrix, You can go straight through Index list
( heavy ) Sort .
For example, three-dimensional array Array :A,A.shape=(x,y,z). be A[index list ] The rearrangement is x The order of the elements . Empathy B.shape=(n,x,y,z), be B[index list ] The rearrangement is n The order of the elements .
Here is a one-dimensional test :
Be careful : Use random.sample
To ensure that the generated index number Different .np.random It doesn't seem to have this function .