tensorflow中random_normal的使用,案例说明,一看便知

先说明函数:
tf.random_normal
tf.random_normal(shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None)

Outputs random values from a normal distribution.

Args:

shape: A 1-D integer Tensor or Python array. The shape of the output tensor.用一个list表示产出的Tensor的形状
mean: A 0-D Tensor or Python value of type dtype. The mean of the normal distribution.均值
stddev: A 0-D Tensor or Python value of type dtype. The standard deviation of the normal distribution.标准差
dtype: The type of the output.数据类型
seed: A Python integer. Used to create a random seed for the distribution. See set_random_seed for behavior.
name: A name for the operation (optional).
Returns:

A tensor of the specified shape filled with random normal values.

案例:

input=tf.random_normal([2, 3, 3, 5]) #生成四维张量,有关各个张量分量的理解,可参考图像卷积博文http://blog.csdn.net/GoodShot/article/details/79653742

sess=tf.Session()
mat=sess.run(input)
print("mat:",mat) #生成四维张量

print("mat[0]:\n",mat[0])
print("mat[0][0]:\n",mat[0][0])
print("mat[0][0][0]:\n",mat[0][0][0])
print("mat[0][0][0][0]:\n",mat[0][0][0][0])
 
print("mat:",mat)
print("mat[1]:\n",mat[1])
print("mat[1][0]:\n",mat[1][0])
print("mat[1][0][0]:\n",mat[1][0][0])
print("mat[1][0][0][0]:\n",mat[1][0][0][0])

第一部分输出:

mat: [[[[ 0.594109   -0.66308975 -0.69155884 -0.51632053  0.25832146]

   [0.01957853  0.16430238 -0.80717999-0.19680725 -0.95925415]

   [0.6863125   0.6016984   1.01236427 -0.7422542   0.64923733]]

 

 [[-0.62370527  0.68413544  0.04029818 1.12874281  0.57089478]

  [-1.74539924 -0.84010768 0.34538889  0.70139134  0.32486886]

  [-0.64678913  0.78401089-0.3739692   2.28909111  0.0142019 ]]

 

 [[-0.83594781  0.45074186  0.54473615 0.65086919 -0.43142638]

  [-0.84368372 -0.05472387 0.78221375 -0.04815574 -0.64128023]

   [0.78006583 -0.22719766  0.09432093-0.19911072  0.10750464]]]

 

 

 [[[-1.95126927 1.71402228 -0.23699592 -0.33628145 0.53677434]

   [ 0.432484  -0.09254493  0.34713465  0.77107131 -0.75730181]

   [-1.91144371 0.46466377 -0.72535664 -0.78066158 1.32734716]]

 

  [[ 0.27377656 -0.89142317 -1.2637589   0.82287949 -1.37860918]

   [ 0.42658806 0.3984631  -0.98085612  0.40774152 1.08501017]

   [-1.93515992 0.8820737   0.95396763  0.96513945 -0.92238081]]

 

  [[-0.38097137 -0.45925513  0.49742085 0.20255992  0.59370619]

   [-0.46083522 -1.08463156 -0.43149    -2.83155179 1.65423214]

   [ 0.11485368 0.05160266 -0.73833942 -0.55305499 1.91214359]]]]

mat[0]:

 [[[0.594109   -0.66308975 -0.69155884-0.51632053  0.25832146]

  [0.01957853  0.16430238 -0.80717999-0.19680725 -0.95925415]

  [0.6863125   0.6016984   1.01236427 -0.7422542   0.64923733]]

 

 [[-0.62370527 0.68413544  0.04029818  1.12874281 0.57089478]

 [-1.74539924 -0.84010768 0.34538889  0.70139134  0.32486886]

 [-0.64678913  0.78401089-0.3739692   2.28909111  0.0142019 ]]

 

 [[-0.83594781 0.45074186  0.54473615  0.65086919 -0.43142638]

 [-0.84368372 -0.05472387 0.78221375 -0.04815574 -0.64128023]

  [0.78006583 -0.22719766  0.09432093-0.19911072  0.10750464]]]

mat[0][0]:

 [[0.594109   -0.66308975 -0.69155884-0.51632053  0.25832146]

 [0.01957853  0.16430238 -0.80717999-0.19680725 -0.95925415]

 [0.6863125   0.6016984   1.01236427 -0.7422542   0.64923733]]

mat[0][0][0]:

 [0.594109   -0.66308975 -0.69155884-0.51632053  0.25832146]

mat[0][0][0][0]:

 0.594109


第二部分输出:


mat: [[[[ 0.594109   -0.66308975 -0.69155884 -0.51632053  0.25832146]

   [0.01957853  0.16430238 -0.80717999-0.19680725 -0.95925415]

   [ 0.6863125   0.6016984  1.01236427 -0.7422542  0.64923733]]

 

 [[-0.62370527  0.68413544  0.04029818 1.12874281  0.57089478]

  [-1.74539924 -0.84010768 0.34538889  0.70139134  0.32486886]

  [-0.64678913  0.78401089-0.3739692   2.28909111  0.0142019 ]]

 

 [[-0.83594781  0.45074186  0.54473615 0.65086919 -0.43142638]

  [-0.84368372 -0.05472387 0.78221375 -0.04815574 -0.64128023]

   [0.78006583 -0.22719766  0.09432093-0.19911072  0.10750464]]]

 

 

 [[[-1.95126927 1.71402228 -0.23699592 -0.33628145 0.53677434]

   [ 0.432484  -0.09254493  0.34713465  0.77107131 -0.75730181]

   [-1.91144371 0.46466377 -0.72535664 -0.78066158 1.32734716]]

 

  [[ 0.27377656 -0.89142317 -1.2637589   0.82287949 -1.37860918]

   [ 0.42658806 0.3984631  -0.98085612  0.40774152 1.08501017]

   [-1.93515992 0.8820737   0.95396763  0.96513945 -0.92238081]]

 

  [[-0.38097137 -0.45925513  0.49742085 0.20255992  0.59370619]

   [-0.46083522 -1.08463156 -0.43149    -2.83155179 1.65423214]

   [ 0.11485368 0.05160266 -0.73833942 -0.55305499 1.91214359]]]]

mat[1]:

 [[[-1.95126927 1.71402228 -0.23699592 -0.33628145 0.53677434]

  [0.432484   -0.09254493  0.34713465 0.77107131 -0.75730181]

 [-1.91144371  0.46466377-0.72535664 -0.78066158  1.32734716]]

 

 [[0.27377656 -0.89142317 -1.2637589  0.82287949 -1.37860918]

  [0.42658806  0.3984631  -0.98085612 0.40774152  1.08501017]

 [-1.93515992  0.8820737   0.95396763 0.96513945 -0.92238081]]

 

 [[-0.38097137 -0.45925513  0.49742085 0.20255992  0.59370619]

 [-0.46083522 -1.08463156 -0.43149   -2.83155179  1.65423214]

  [0.11485368  0.05160266 -0.73833942-0.55305499  1.91214359]]]

mat[1][0]:

 [[-1.95126927 1.71402228 -0.23699592 -0.33628145 0.53677434]

 [0.432484   -0.09254493  0.34713465 0.77107131 -0.75730181]

 [-1.91144371 0.46466377 -0.72535664 -0.78066158 1.32734716]]

mat[1][0][0]:

 [-1.95126927 1.71402228 -0.23699592 -0.33628145 0.53677434]

mat[1][0][0][0]:

 -1.95127

 



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值