# tf.truncated_normal_initializer()和tf.random_normal_initializer()的区别和使用

tf.random_normal_initializer：正态分布
tf.truncated_normal_initializer：截取的正态分布

# 1. 截取的正态分布tf.truncated_normal_initializer(mean=0.0, stddev=0.1, seed=3)

• 截取的正态分布：就是生成的值中不包括大于平均值2个标准偏差的值

mean：一个python标量或一个标量张量。要生成的随机值的均值。
stddev：一个python标量或一个标量张量。要生成的随机值的标准偏差。

# 2. 正态分布tf.random_normal_initializer(mean=0.0, stddev=0.1, seed=3)

a = tf.get_variable(name='a', shape=[100], dtype=tf.float32,
initializer=tf.truncated_normal_initializer(mean=0.0, stddev=0.1, seed=3))

b = tf.get_variable(name='b', shape=[100], dtype=tf.float32,
initializer=tf.random_normal_initializer(mean=0.0, stddev=0.1, seed=3))
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(sess.run(a))
'''
里面没有大于0.2和小于-0.2的
[ 0.10616621 -0.08785783  0.01118722  0.01851172 -0.01623348 -0.0891386
-0.08166396  0.06149269  0.08271172  0.16055219  0.04169592 -0.10686195
-0.01665053 -0.03023496 -0.12736471  0.06307661 -0.01437783  0.03876389
-0.10972794  0.12655747  0.11687908 -0.03214856  0.02935706  0.00762281
-0.12204427 -0.10294425 -0.00763864  0.03461294 -0.19703506  0.10607665
0.10709941 -0.01405733 -0.1617376  -0.05163575 -0.08488546 -0.04801231
-0.0505003   0.13330936  0.00269773 -0.08263079  0.0511817  -0.04211122
0.0193577  -0.137345   -0.18103935  0.01766641  0.148498    0.06402254
-0.03841636 -0.04187259  0.04987392 -0.02448696  0.1287862   0.0503306
-0.02708706 -0.00893697 -0.06353955 -0.00131033  0.18348219 -0.02506754
-0.01997366 -0.03023654 -0.04602637  0.02520993  0.02981526 -0.12124653
-0.03639168 -0.08904971  0.05320144 -0.07793494  0.02164084  0.08272161
0.02077272 -0.07708595  0.09061582 -0.13072734  0.02396685  0.03242476
0.10640353 -0.03792128  0.02185469  0.10510571  0.0181055   0.07277361
0.00447241 -0.14514762 -0.10348066  0.10740198  0.07852708  0.1552333
0.02378579 -0.11217902  0.01159469 -0.02898889  0.01798819 -0.14918141
-0.0262782   0.02342361  0.09656129  0.09289192]
'''
print(sess.run(b))
'''
里面有大于0.2和小于-0.2的
[ 0.10616621 -0.08785783  0.01118722  0.01851172  0.09092256 -0.07378723
0.03001501  0.1742887  -0.00631655 -0.13077314  0.01601363 -0.14507413
-0.20488241  0.21855004  0.11234913  0.13033779 -0.13351914 -0.09540799
-0.02634776 -0.10972204  0.01456714 -0.03583914 -0.00084517 -0.22827044
-0.08937468  0.09186908 -0.10620292 -0.02304745  0.09695566 -0.10061815
0.00192356 -0.27305534 -0.05199259 -0.06177432 -0.16419438  0.02565547
0.0664131   0.01141317 -0.05671817 -0.08842032  0.18958855 -0.02386647
0.17845856  0.15865237  0.1111358  -0.03968054  0.16598205 -0.12557156
-0.02987569 -0.01402317  0.07884285  0.08311015  0.2582669   0.04092367
0.04389277 -0.03522856  0.01525367 -0.04576964  0.10028755  0.06468149
-0.08214067 -0.10676246 -0.08544166 -0.00071732  0.08378523  0.02149109
-0.00446716 -0.1527795  -0.18233398 -0.15732548  0.19334795 -0.15728667
-0.14556453 -0.00830592  0.00787988  0.02187095 -0.09248024 -0.01711406
0.15319322  0.01542161  0.11044683 -0.01526301 -0.08834147  0.00522408
-0.11273849 -0.04034163 -0.04827607  0.09010233 -0.02059369  0.21848594
-0.12490624  0.11763942 -0.01928969 -0.08238891  0.15416537 -0.136229
0.04558441 -0.01676318 -0.05967107 -0.06587494]
'''


©️2019 CSDN 皮肤主题: 深蓝海洋 设计师: CSDN官方博客