IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    [原]AI学习之路(13): 创建随机张量3

    caimouse发表于 2017-03-01 09:57:58
    love 0

    tf.random_uniform(shape, minval=0, maxval=None, dtype=tf.float32, seed=None, name=None)

    均匀分布(Uniform Distribution)是概率统计中的重要分布之一。顾名思义,均匀,表示可能性相等的含义。

     

    参数:

    shape: 一维整数张量或者Python数组,用来说明行列形式。

    minval: 0维张量或者Python的数值。表示生成随机值的下限。

    maxval: 0维张量或者Python的数值。表示生成随机值的上限。

    dtype: 输出张量的类型。

    seed: Python整数,用来产生随机的种子。

    name: 张量的名称。

    返回值:

    返回平均分布的随机张量。

     

    例子:

    #python 3.5.3  蔡军生  
    #http://edu.csdn.net/course/detail/2592  
    #
    
    import tensorflow as tf
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    
    #绘制直方图
    def drawHist(heights):
        #创建直方图
        #第一个参数为待绘制的定量数据,不同于定性数据,这里并没有事先进行频数统计
        #第二个参数为划分的区间个数
        plt.hist(heights, 100)
        plt.xlabel('Value')
        plt.ylabel('Frequency')
        plt.title('Test')
        plt.show()
        
    #创建张量常量
    x = tf.random_uniform(shape=[20000], minval=-1.0,maxval=1.0,dtype=tf.float32)
    
    #显示它的值
    init_op = tf.global_variables_initializer()
    with tf.Session() as sess:
        sess.run(init_op)
        print(x.eval())
        drawHist(x.eval())

    输出结果:



    1. C++标准模板库从入门到精通 

    http://edu.csdn.net/course/detail/3324

    2.跟老菜鸟学C++

    http://edu.csdn.net/course/detail/2901

    3. 跟老菜鸟学python

    http://edu.csdn.net/course/detail/2592

    4. 在VC2015里学会使用tinyxml库

    http://edu.csdn.net/course/detail/2590

    5. 在Windows下SVN的版本管理与实战 

     http://edu.csdn.net/course/detail/2579

    6.Visual Studio 2015开发C++程序的基本使用 

    http://edu.csdn.net/course/detail/2570

    7.在VC2015里使用protobuf协议

    http://edu.csdn.net/course/detail/2582

    8.在VC2015里学会使用MySQL数据库

    http://edu.csdn.net/course/detail/2672



沪ICP备19023445号-2号
友情链接