>>> 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. 入门拾遗 day2

    一.类和对象 对于Python,一切事物都是对象,对象基于类创建 学会查看帮助 type(类型名) 查看对象的类型dir(类型名) 查看类中提供的所有功能help(类型名) 查看类中所有详细的功能he ...

  2. Cpython-并发编程

    阅读目录 一 背景知识 二 python并发编程之多进程 三 python并发编程之多线程 四 python并发编程之协程 五 python并发编程之IO模型 六 补充:paramiko模块 七 作业 ...

  3. SharePoint 2010 以Jquery Ajax方式更新SharePoint列表数据!

    之前本人的博客介绍了<sharepoint 2010自定义访问日志列表设置移动终端否和客户端访问系统等计算列的公式>,那如何通过Jquery提交访问日志到自定义的SharePoint的访问 ...

  4. springmvc 自定义拦截器

    <mvc:interceptors> <!-- 配置自定义的拦截器 --> <bean class="com.atguigu.springmvc.interce ...

  5. Github 的其他用法

    一.概述 Github 除了作为代码托管库外,有趣的程序员们还利用它解锁了有趣的新姿势. 二.新姿势 2.1 Github Pages 可以为项目建立静态主页(即gh-pages分支), 也可以建立命 ...

  6. python学习笔记:函数参数

    1. 位置参数:一般的参数 2. 默认参数: def power(x, n=2): s = 1 while n > 0: n = n - 1 s = s * x return s 参数里有默认赋 ...

  7. Linux网络性能评估工具iperf 、CHARIOT测试网络吞吐量

    网络性能评估主要是监测网络带宽的使用率,将网络带宽利用最大化是保证网络性能的基础,但是由于网络设计不合理.网络存在安全漏洞等原因,都会导致网络带宽利用率不高.要找到网络带宽利用率不高的原因,就需要对网 ...

  8. cisco笔记

    交换机 show cdp neighbors 显示邻居信息 路由 show ip interface brief 显示接口ip

  9. Git常用分支操作

    新建分支 git branch branchname 切换到分支dev git checkout branchname 查看所有的分支信息 git branch -a 查看远程分支信息 git bra ...

  10. [nowcoder]最长区间

    链接:https://www.nowcoder.com/acm/contest/158/B 求最长连续严格递增序列 线段树模板题,码力弱的一匹调了半天.. 代码: #include<iostre ...