小编pul*_*tag的帖子

NumPy随机种子产生不同的随机数

我运行以下代码:

 np.random.RandomState(3)
 idx1 = np.random.choice(range(20),(5,))
 idx2 = np.random.choice(range(20),(5,))  
 np.random.RandomState(3)
 idx1S = np.random.choice(range(20),(5,))
 idx2S = np.random.choice(range(20),(5,))       
Run Code Online (Sandbox Code Playgroud)

我得到的输出如下:

idx1:  array([ 2, 19, 19,  9,  4])  
idx1S: array([ 2, 19, 19,  9,  4])  

idx2:  array([ 9,  2,  7, 10,  6]) 
idx2S: array([ 5, 16,  9, 11, 15]) 
Run Code Online (Sandbox Code Playgroud)

idx1和idx1S匹配,但idx2和idx2S不匹配.我希望一旦我为随机数生成器播种并重复相同的命令序列 - 它应该产生相同的随机数序列.这不是真的吗?或者还有其他我想念的东西?

python random numpy

6
推荐指数
2
解决办法
1572
查看次数

标签 统计

numpy ×1

python ×1

random ×1