tf.truncated_normal

tf.truncated_normal(shape, mean, stddev) :shape表示生成张量的维度,mean是均值,stddev是标准差。这个函数产生正太分布,均值和标准差自己设定。这是一个截断的产生正太分布的函数,就是说产生正太分布的值如果与均值的差值大于两倍的标准差,那就重新生成。

例:

import tensorflow as tf;
import numpy as np;
import matplotlib.pyplot as plt;
     
c = tf.truncated_normal(shape=[10,10], mean=0, stddev=1)
     
with tf.Session() as sess:
    print sess.run(c)


输出:
--------------------------------------------------------------------------
[[ 0.21928115 -0.28152597 -0.7381363  -0.48565105 -0.0991328  -0.2203394
  -1.0337437  -1.3260287  -0.0947044   0.29130432]
 [-0.32038376 -0.14401251 -0.3000437   1.90986    -0.02789464 -1.75405
   0.75386107  0.40255374  0.50969696 -0.5144246 ]
 [-0.05934289 -0.13676012 -0.8187295   1.4812258  -0.7164898   0.31804
  -0.11366758 -0.22108728 -0.2409874   0.36390948]
 [ 1.709577   -0.20038871  0.40611205  0.9113553  -0.29350016  0.7514032
   0.10839624 -0.46098515  0.557274    0.38821268]
 [ 0.48130617  1.1131536  -1.1356065   0.41551134  0.14280558  0.56424123
  -1.1711147  -0.58633757 -0.4785279  -1.3436842 ]
 [-0.9562587  -0.20193478 -0.7506948   0.9922889  -0.7112647  -1.2335519
  -1.0257992   0.18601827 -1.9078422  -0.57947254]
 [-0.18983668 -0.59639853  0.1502351  -0.952213   -0.56599045 -0.4365256
   1.390264    0.06290046  1.9184309   0.39992943]
 [-0.16891228  0.7881672  -0.47331563  1.9109113   0.44252422 -0.12054163
  -0.42039979 -0.65125275  0.02856164 -1.2874403 ]
 [-0.15257804 -1.0795212   0.3381369   0.26832175  0.40943214  0.4222502
   0.34631294 -0.10362091  0.70107377 -1.5168688 ]
 [ 0.5576659   0.45390686 -0.7741634   1.3609529  -0.13846219 -0.31193045
   0.06494585  0.52165216 -1.7784148  -1.1660533 ]]
----------------------------------------------------------------------------

转载地址:https://blog.csdn.net/uestc_c2_403/article/details/72235565

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券