Python Programming learning :random.shuffle An introduction to the 、 A detailed introduction to how to use
Catalog
random.shuffle An introduction to the
random.shuffle How to use
1、 Disarrange two lists and follow the same rule
random.shuffle Method , Reorder elements , Upset the original order , Returns a random sequence ( Of course, the random sequence here belongs to pseudorandom , Can be reproduced ), This method is similar to shuffling .
import random
X_lists = [[1,2,3,4,5],
[11,12,13,14,15],
[21,22,23,24,25],
[31,32,33,34,35],
[41,42,43,44,45]]
y_lists = [0,10,20,30,40]
print("before:",X_lists,'\n',y_lists)
# # T1、 utilize random Function implementation
# random.seed(123)
# random.shuffle(X_lists) #shuffle Method
# random.seed(123) # For similar data , Random execution of the same rule , This line must be added
# random.shuffle(y_lists)
# print("after:",X_lists,'\n',y_lists)
# T2、 utilize np.random Function implementation
import numpy as np
np.random.seed(123)
np.random.shuffle(X_lists)
np.random.seed(123) # For similar data , Random execution of the same rule , This line must be added
np.random.shuffle(y_lists)
print("after:",X_lists,'\n',y_lists)