zoukankan      html  css  js  c++  java
  • tensorflow的一些函数

    1.tf.constant(value,dtype=None,shape=None,name='Const')

    注意这个函数创造的是一个常数tensor,而不是一个具体的常数

    value:即可以是list,也可以是value

    dtype:对应生成的tensor里的元素的类型

    # Constant 1-D Tensor populated with value list.
     tensor = tf.constant([1, 2, 3, 4, 5, 6, 7]) => [1 2 3 4 5 6 7]              注意这种直接加入list的情况
    
     # Constant 2-D tensor populated with scalar value -1.
     tensor = tf.constant(-1.0, shape=[2, 3]) => [[-1. -1. -1.]
                                                  [-1. -1. -1.]]

    对于value给tensor,并不是不能shape形状,如果shape出来value中的元素不够用时,就以最后一个元素重复出现填充至满足形状。

    以下实例:

    >>> sess = tf.InteractiveSession()
    
    >>> a = tf.constant([1,2,3],shape = [6])
    >>> b = tf.constant([1,2,3],shape = [3,2])
    >>> c = tf.constant([1,2,3],shape = [2,3])
    
    >>> print sess.run(a)
    [1 2 3 3 3 3]
    >>> print sess.run(b)
    [[1 2]
     [3 3]
     [3 3]]
    >>> print sess.run(c)
    [[1 2 3]
     [3 3 3]]

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

    这个函数是从截断的正态分布产生随机数

    mean:均值

    stddev:标准差

  • 相关阅读:
    理解java的接口和抽象类
    Yum 仓库配置
    Vsftp 服务配置
    SAMBA 服务配置
    DHCP 服务配置
    dd 命令的使用
    linux 账户控制
    CentOS 系统优化
    Page Cache与Page回写
    TCP拥塞控制
  • 原文地址:https://www.cnblogs.com/ymjyqsx/p/6530016.html
Copyright © 2011-2022 走看看