python随机数种子在多维数组的使用

624次阅读
没有评论

python随机数种子在多维数组的使用

python随机数种子

1、运行test_mult_shape函数,设定相同的随机数组,两次运行两个一行的多维正态分布的结果。

与一次运行两行的多维正态分布的结果的第一行完全相同。

2、对相同类型的随机数分布,形状特征不会影响分布的生成秩序。

程序中,np.random.randn(1, 2),这一行不像是第二次运行多维正态分布的随机数组,它”几乎”是后缀于它的前一行一次性生成的。

python随机数种子使用实例

import random
 
# print(help(random))
 
def test_random_seed_in_std_lib(seed=0, cnt=3):
    random.seed(seed)
    print("test seed: ", seed)
    for _ in range(cnt):
        print(random.random())
        print(random.randint(0,100))
        print(random.uniform(1, 10))
        print('\n')
test_random_seed_in_std_lib()
test seed:  0
0.8444218515250481
97
9.01219528753418
 
0.04048437818077755
65
5.373349269065314
 
0.9182343317851318
38
9.710199954281542
test_random_seed_in_std_lib()
test seed:  0
0.8444218515250481
97
9.01219528753418
 
0.04048437818077755
65
5.373349269065314
 
0.9182343317851318
38
9.710199954281542
test_random_seed_in_std_lib(99)
test seed:  99
0.40397807494366633
25
6.39495190686897
 
0.23026272839629136
17
7.8388969285727015
 
0.2511510083752201
49
5.777313434770537

以上就是python随机数种子在多维数组的使用,希望对大家有所帮助。

神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2022-03-24发表,共计985字。
新手QQ群:570568346,欢迎进群讨论 Python51学习