为 numpy uniform 设置种子不会导致相同的概率
Setting a seed for numpy uniform doesn't result in the same probabilities
为什么下面显示的代码没有产生 3 个具有相同概率的数组?如何生成可重现的概率?
import numpy as np
np.random.seed(42)
for i in range(3):
print(np.random.uniform(size = 10))
[0.37454012 0.95071431 0.73199394 0.59865848 0.15601864 0.15599452
0.05808361 0.86617615 0.60111501 0.70807258]
[0.02058449 0.96990985 0.83244264 0.21233911 0.18182497 0.18340451
0.30424224 0.52475643 0.43194502 0.29122914]
[0.61185289 0.13949386 0.29214465 0.36636184 0.45606998 0.78517596
0.19967378 0.51423444 0.59241457 0.04645041]
您应该在每个循环开始时重置种子。
import numpy as np
for i in range(3):
np.random.seed(42)
print(np.random.uniform(size = 10))
[0.37454012 0.95071431 0.73199394 0.59865848 0.15601864 0.15599452
0.05808361 0.86617615 0.60111501 0.70807258]
[0.37454012 0.95071431 0.73199394 0.59865848 0.15601864 0.15599452
0.05808361 0.86617615 0.60111501 0.70807258]
[0.37454012 0.95071431 0.73199394 0.59865848 0.15601864 0.15599452
0.05808361 0.86617615 0.60111501 0.70807258]
为什么下面显示的代码没有产生 3 个具有相同概率的数组?如何生成可重现的概率?
import numpy as np
np.random.seed(42)
for i in range(3):
print(np.random.uniform(size = 10))
[0.37454012 0.95071431 0.73199394 0.59865848 0.15601864 0.15599452
0.05808361 0.86617615 0.60111501 0.70807258]
[0.02058449 0.96990985 0.83244264 0.21233911 0.18182497 0.18340451
0.30424224 0.52475643 0.43194502 0.29122914]
[0.61185289 0.13949386 0.29214465 0.36636184 0.45606998 0.78517596
0.19967378 0.51423444 0.59241457 0.04645041]
您应该在每个循环开始时重置种子。
import numpy as np
for i in range(3):
np.random.seed(42)
print(np.random.uniform(size = 10))
[0.37454012 0.95071431 0.73199394 0.59865848 0.15601864 0.15599452
0.05808361 0.86617615 0.60111501 0.70807258]
[0.37454012 0.95071431 0.73199394 0.59865848 0.15601864 0.15599452
0.05808361 0.86617615 0.60111501 0.70807258]
[0.37454012 0.95071431 0.73199394 0.59865848 0.15601864 0.15599452
0.05808361 0.86617615 0.60111501 0.70807258]