>>> 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. Flume日志收集 总结

    Flume是一个分布式.可靠.和高可用的海量日志聚合的系统,支持在系统中定制各类数据发送方,用于收集数据: 同时,Flume提供对数据进行简单处理,并写到各种数据接受方(可定制)的能力. (1) 可靠 ...

  2. 第一节、Alex 讲解 python+mysql 交互;

    Python Mysql 交互 A.Alex 的语法展示: import MySQLdb  try:      conn=MySQL.connect(host='localhost',user='ro ...

  3. 自己写的一个简单PHP采集器

    自己写的一个简单PHP采集器 <?php //**************************************************************** $url = &q ...

  4. react下将输入的汉字转化为拼音

    1.首先需要一个简单的拼音和汉字对应的字典文件: /** * 收录常用汉字6763个,不支持声调,支持多音字,并按照汉字使用频率由低到高排序 */ var pinyin_dict_notone = { ...

  5. linux命令(6/10):find 命令

    Linux将时钟分为系统时钟(System Clock)和硬件(Real Time Clock,简称RTC)时钟两种.系统时间是指当前Linux Kernel中的时钟, 而硬件时钟则是主板上由电池供电 ...

  6. JavaScript传递的是引用的副本

    看例子 var test1 = function (args) { args.name = "lcc2"; args = { name: "lcc3" }; } ...

  7. 20145109 《Java程序设计》第四周学习总结

    20145109 <Java程序设计>第四周学习总结 教材学习内容总结 Chapter 6 Inheritance & Polymorphism What is Inheritan ...

  8. Hungry Rabbit

    Problem C. Hungry Rabbit Input file: hungry.in Output file: hungry.out Time limit: 10 seconds Memory ...

  9. Prims算法 - 最小生成树

    2017-07-26  14:35:49 Prims算法,是一种基于“贪心”的求最小树的算法 ,以每次加入一个邻接边来建立最小树,直到找到N-1个边为止. 规则:以开始时生成树的集合为起始的顶点,然后 ...

  10. Search In Rotated SortedArray2, 有重复数据的反转序列。例如13111.

    问题描述:反转序列,但是有重复的元素,例如序列13111. 算法思路:如果元素有重复,那么left-mid,就不一定是有序的了,所以不能利用二分搜索,二分搜索必须是局部有序.针对有序序列的反转,如果有 ...