我是靠谱客的博主 甜蜜香菇,最近开发中收集的这篇文章主要介绍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




最后

以上就是甜蜜香菇为你收集整理的tensorflow中random_normal的使用,案例说明,一看便知的全部内容,希望文章能够帮你解决tensorflow中random_normal的使用,案例说明,一看便知所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(38)

评论列表共有 0 条评论

立即
投稿
返回
顶部