之前在思考这两个函数产生的随机排列,是否能够复现,然后通过实验发现。
运行以下代码:
import numpy as np
np.random.seed(12)
random_index1=np.random.permutation(np.arange(10))
print("第一次运行:",random_index1)
random_index2=np.random.permutation(np.arange(10))
print("第一次运行:",random_index2)
输出:
第一次运行: [5 8 7 0 4 9 3 2 1 6]
第一次运行: [6 0 9 7 3 2 1 8 5 4]
然后发现,无论什么时候运行这段代码,只要seed=12没有更改,那么输出都是一样的。这样就比较方便的能够代码的随机过程了。