TensorFlow tf.random_normal函数说明

函数形式:

tf.random_normal(
    shape,
    mean=0.0,
    stddev=1.0,
    dtype=tf.float32,
    seed=None,
    name=None
)

参数:

  1. shape: 输出张量的形状,必选
  2. mean: 正态分布的均值,默认为0
  3. stddev: 正态分布的标准差,默认为1.0
  4. dtype: 输出的类型,默认为tf.float32
  5. seed: 随机数种子,是一个整数,当设置之后,每次生成的随机数都一样
  6. name: 操作的名称

用途:用于从服从指定正态分布的数值中取出随机数。

代码示例:

# output1每次运行的结果不同
output1 = tf.Variable(tf.random_normal([2], stddev=0.1))
# seed设置数值,每次生成的结果相同
output2 = tf.Variable(tf.random_normal([2, 3], stddev=1, seed=1))

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(output1)
    print(output2)
    print(sess.run(output1))
    print(sess.run(output2))

运行结果:

<tf.Variable 'Variable_33:0' shape=(2,) dtype=float32_ref>
<tf.Variable 'Variable_34:0' shape=(2, 3) dtype=float32_ref>
[0.03875994 0.00234846]
[[-0.8113182   1.4845988   0.06532937]
 [-2.4427042   0.0992484   0.5912243 ]]

 

参考:https://blog.csdn.net/kdongyi/article/details/82380409

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值