tf.random_normal()函数

@





				版权声明:本文为博主原创文章,转载请注明出处。					https://blog.csdn.net/dcrmg/article/details/79028043				</div>
							<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-f57960eb32.css">
							            <link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-f57960eb32.css">
					<div class="htmledit_views" id="content_views">

tf.random_normal()函数用于从服从指定正太分布的数值中取出指定个数的值。

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

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

以下程序定义一个w1变量:


 
 
  1. # -*- coding: utf-8 -*-)
  2. import tensorflow as tf
  3. w1 = tf.Variable(tf.random_normal([ 2, 3], stddev= 1, seed= 1))
  4. with tf.Session() as sess:
  5. sess.run(tf.global_variables_initializer())
  6. # sess.run(tf.initialize_all_variables()) #比较旧一点的初始化变量方法
  7. print w1
  8. print sess.run(w1)
输出:


 
 
  1. <tf.Variable 'Variable:0' shape=( 2, 3) dtype=float32_ref>
  2. [[ -0.81131822 1.48459876 0.06532937]
  3. [ -2.4427042 0.0992484 0.59122431]]

变量w1声明之后并没有被赋值,需要在Session中调用run(tf.global_variables_initializer())方法初始化之后才会被具体赋值。

tf中张量与常规向量不同的是执行"print w1"输出的是w1的形状和数据类型等属性信息,获取w1的值需要调用sess.run(w1)方法。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值