import numpy as np num_train = 10 indices = list(range(num_train)) print(indices) print(len(indices)) np.random.seed(2) np.random.shuffle(indices) print(indices)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 10 [4, 1, 5, 0, 7, 2, 3, 6, 9, 8]
注意:当np.random.seed()不设置数字时,上述代码的运行结果都可能不同。
当np.random.seed()设置数字后,每次运行代码的结果都相同。但结果会因为所设置的数字不同而发生变化。所设置的数字可以是任意整数。
import numpy as np num_train = 10 x_train = list(range(num_train)) y_train = list(range(num_train)) np.random.seed(7) np.random.shuffle(x_train) np.random.seed(7) np.random.shuffle(y_train) print(x_train) print(y_train)
[8, 5, 0, 2, 1, 9, 7, 3, 6, 4] [8, 5, 0, 2, 1, 9, 7, 3, 6, 4]
REF
https://blog.csdn.net/2201_75349501/article/details/128383564
标签:shuffle,random,num,train,np,seed From: https://www.cnblogs.com/emanlee/p/17128262.html