numpy.random.seed():用于指定随机数生成时使用算法的开始值,如果没有指定每次生成的值都不一样
如果不指定seed的值,那么每次随机生成的数字都不一样:
In [17]: import numpy as npIn [18]: i = 0In [19]: while i < 5:...: print(np.random.random())...: i += 1...: 0.6024396750158225 0.9269520884112016 0.012892523215978668 0.5537467163325156 0.6240533935003028
可以看出每次随机生成的值都不一样。
现在我们指定seed的值:
In [27]: while i < 5:...: np.random.seed(100)...: print(np.random.random())...: i += 1...: 0.5434049417909654 0.5434049417909654 0.5434049417909654 0.5434049417909654 0.5434049417909654
In [17]: import numpy as np
In [18]: i = 0
In [19]: while i < 5: ...: print(np.random.random()) ...: i += 1 ...:0.60243967501582250.92695208841120160.0128925232159786680.55374671633251560.6240533935003028