python随机数种子在多维数组的使用
发布时间:2024-07-04 14:29:02

说明
1、运行test_运行test_mult_shape函数,设置相同的随机数组,两行多维正态分布结果。
多维正态分布的结果与一次运行两行的第一行完全相同。
2、对于相同类型的随机数分布,形状特征不影响分布的生成秩序。
程序中,np.random.randn(1, 2)这一行不像是第二次运行多维正态分布的随机数组。"几乎"它的前一行一次性生成后缀。
实例
importrandom
#print(help(random))
deftest_random_seed_in_std_lib(seed=0,cnt=3):
random.seed(seed)
print("testseed:",seed)
for_inrange(cnt):
print(random.random())
print(random.randint(0,100))
print(random.uniform(1,10))
print('\n')
test_random_seed_in_std_lib()
testseed:0
0.8444218515250481
97
9.01219528753418
0.04048437818077755
65
5.373349269065314
0.9182343317851318
38
9.710199954281542
test_random_seed_in_std_lib()
testseed:0
0.8444218515250481
97
9.01219528753418
0.04048437818077755
65
5.373349269065314
0.9182343317851318
38
9.710199954281542
test_random_seed_in_std_lib(99)
testseed:99
0.40397807494366633
25
6.39495190686897
0.23026272839629136
17
7.8388969285727015
0.2511510083752201
49
5.777313434770537以上是python随机数种子在多维数组中的使用,希望对大家有所帮助。更多Python学习指导:python基础教程
本文教程操作环境:windows7系统Python 3.9.1,DELL G3电脑。
下一篇 python随机数种子的特性
