>>> import tensorflow as tf
>>> a=tf.constant([[1,2],[3,4]])
>>> b=tf.constant([6,6])
>>> result=tf.add(a,b)
>>> sess=tf.Session()
>>> sess.run(result)
array([[ 7,  8],
       [ 9, 10]], dtype=int32)
>>> c=tf.constant([[1,2,3],[4,5,6]])
>>> result3=a*b
>>> sess.run(result3)
array([[ 6, 12],

[18, 24]], dtype=int32)>>> x1=tf.constant([[1,2],[3,4]],name="x1")

>>> x1=tf.constant([[1,2],[3,4]],name="x1")
>>> x2=tf.constant([[11,22],[33,44]],name="x2")

>>> y=tf.matmul(x1,x2)
>>> sess.run(y)
array([[ 77, 110],
       [165, 242]], dtype=int32)

>>> x3=tf.constant([[10,20],],name="x3")
>>> z=tf.matmul(x3,x1)
>>> sess.run(z)
array([[ 70, 100]], dtype=int32)

#正太分布

>>> n1=tf.random_normal([2,3],mean=5,stddev=2)

#正太分布,随机值偏离平均值超过2个标准差,会重新生成新的随机数,避免产生统计学上的异常数据。

>>> n2=tf.truncated_normal([2,3],mean=6,stddev=1)

#平均分布
>>> n3=tf.random_uniform([2,3],minval=5,maxval=20)

#gamma分布

>>> n4=tf.random_gamma([2,3],alpha=1.5,beta=2.9)

>>> sess.run(n1)
array([[ 1.70361972,  0.65788937,  7.08583546],
       [ 5.49968147,  2.47537422,  7.47936249]], dtype=float32)
>>> sess.run(n2)
array([[ 5.51383209,  5.28713369,  5.9794035 ],
       [ 5.45024824,  6.65198326,  4.69569492]], dtype=float32)
>>> sess.run(n3)
array([[  9.39581871,  13.13985538,  17.50672722],
       [ 10.08992577,  15.1558075 ,  18.60567093]], dtype=float32)
>>> sess.run(n4)
array([[ 0.3365562 ,  0.27886772,  0.8982302 ],
       [ 0.21223408,  0.95498532,  1.72396851]], dtype=float32)

>>> n5=tf.Variable(tf.random_normal([2,3],mean=8,stddev=2))

>>> m1=tf.zeros([2,2],tf.int32)
>>> m2=tf.ones([2,2],tf.float32)
>>> m3=tf.fill([2,2],66)

>>> sess.run(m1)
array([[0, 0],
       [0, 0]], dtype=int32)
>>> sess.run(m2)
array([[ 1.,  1.],
       [ 1.,  1.]], dtype=float32)
>>> sess.run(m3)
array([[66, 66],
       [66, 66]], dtype=int32)

TF随笔-4的更多相关文章

  1. TF随笔-13

    import tensorflow as tf a=tf.constant(5) b=tf.constant(3) res1=tf.divide(a,b) res2=tf.div(a,b) with ...

  2. TF随笔-11

    #!/usr/bin/env python2 # -*- coding: utf-8 -*- import tensorflow as tf my_var=tf.Variable(0.) step=t ...

  3. TF随笔-10

    #!/usr/bin/env python# -*- coding: utf-8 -*-import tensorflow as tf x = tf.constant(2)y = tf.constan ...

  4. TF随笔-9

    计算累加 #!/usr/bin/env python2 # -*- coding: utf-8 -*-"""Created on Mon Jul 24 08:25:41 ...

  5. TF随笔-8

    #!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Mon Jul 10 09:35:04 201 ...

  6. TF随笔-7

    求平均值的函数 reduce_mean axis为1表示求行 axis为0表示求列 >>> xxx=tf.constant([[1., 10.],[3.,30.]])>> ...

  7. tf随笔-6

    import tensorflow as tfx=tf.constant([-0.2,0.5,43.98,-23.1,26.58])y=tf.clip_by_value(x,1e-10,1.0)ses ...

  8. tf随笔-5

    # -*- coding: utf-8 -*-import tensorflow as tfw1=tf.Variable(tf.random_normal([2,6],stddev=1))w2=tf. ...

  9. TF随笔-3

    >>> import tensorflow as tf>>> node1 = tf.constant(3.0, dtype=tf.float32)>>& ...

随机推荐

  1. Java集合(5):HashSet

    存入Set的每个元素必须是惟一的,因为Set不保存重复元素.加入Set的元素必须定义equals()方法以确保对象的唯一性.Set不保证维护元素的次序.Set与Collection有完全一样的接口. ...

  2. thinkphp api架构搭建

    1.结构搭建 模块下面使用 controller , model ,service,validate分别对应的作用 controller控制器里面可以进行分版本 v1,v2之类的,不过要访问通必须配置 ...

  3. Linux Shell编程 exit、break、continue

    exit语句 在系统中exit 命令用于退出当前用户的登录状态.在 Shell 脚本中exit 语句是用来退出当前脚本. exit 的语法如下: exit [返回值] 如果在 exit 之后定义了返回 ...

  4. Environment类包含的几个有用的方法

    1.获取操作系统版本(PC,PDA均支持) Environment.OSVersion 2.获取应用程序当前目录(PC支持) Environment.CurrentDirectory 3.列举本地硬盘 ...

  5. 【Flask】Flask上下文

    # 上下文: ### Local对象:在`Flask`中,类似于`request`的对象,其实是绑定到了一个`werkzeug.local.Local`对象上.这样,即使是同一个对象,那么在多个线程中 ...

  6. Linux 设置中文编码

    Linux 设置中文编码 1.测试是否存在字体列表 fc-list 2.安装字体列表包 yum -y install fontconfig 3.去win系统中找到拷贝字体文件. 路径:C:/Windo ...

  7. 华为S5700系列交换机AR配置静态IP双链路负载分担

    适用于:有多个以太WAN口的机型. 业务需求: 运营商1分配的接口IP为100.100.1.2,子网掩码为255.255.255.252,网关IP为100.100.1.1. 运营商2分配的接口IP为2 ...

  8. Linux系统运行级别配置

    Linux的运行级别 Linux的运行级别有七种,可以通过查看/etc/inittab文件进行了解: Level0:系统停机状态,默认系统运行级别不能设置为0,否则系统不能正常启动: Level1:单 ...

  9. [nowcoder]再编号

    链接:https://www.nowcoder.com/acm/contest/158/C 每变化一次,tot=tot*(n-1),且每两个数之差delta*=-1,直接根据这两个性质暴力循环1000 ...

  10. fabric安装使用

    可以使用pip安装fabric,注意使用pip 安装fabric时,一定要指定版本,不要安装2.0版本的,无论怎样都会提示没有api这样模块,所以指定安装 pip install fabric==1. ...