tf随笔-1】的更多相关文章

import tensorflow as tf a=tf.constant(5) b=tf.constant(3) res1=tf.divide(a,b) res2=tf.div(a,b) with tf.Session() as sess: print sess.run(res1) print sess.run(res2) 输出: 1.666666666671…
#!/usr/bin/env python2 # -*- coding: utf-8 -*- import tensorflow as tf my_var=tf.Variable(0.) step=tf.Variable(0,trainable=False) ema=tf.train.ExponentialMovingAverage(0.99,step) maintain_average_op=ema.apply([my_var]) with tf.Session() as sess: init…
#!/usr/bin/env python# -*- coding: utf-8 -*-import tensorflow as tf x = tf.constant(2)y = tf.constant(20)z = tf.Variable([[6,1,2],[3,4,5],[0,0,0],[8,2,4]])mask=z[:,0]>0res = tf.boolean_mask(z,mask)init_assign = tf.global_variables_initializer()with t…
计算累加 #!/usr/bin/env python2 # -*- coding: utf-8 -*-"""Created on Mon Jul 24 08:25:41 2017求1+...+5@author: myhaspl@myhaspl.com"""import tensorflow as tfi = tf.constant(0)num_sum=tf.Variable(0)def cond(i,num_sum):    return i &…
#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Mon Jul 10 09:35:04 2017 @author: myhaspl@myhaspl.com,http://blog.csdn.net/myhaspl """ #逻辑或 import tensorflow as tf batch_size=10 w1=tf.Variable(tf.random_normal([…
求平均值的函数 reduce_mean axis为1表示求行 axis为0表示求列 >>> xxx=tf.constant([[1., 10.],[3.,30.]])>>> sess.run(xxx)array([[  1.,  10.],       [  3.,  30.]], dtype=float32)>>> mymean=tf.reduce_mean(xxx,0)>>> sess.run(mymean)array([  2.…
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)sess=tf.Session()print sess.run(y) sess.close() clip_by_value(    t,    clip_value_min,    clip_value_max,    name=None) Given a tensor t, this operation…
# -*- coding: utf-8 -*-import tensorflow as tfw1=tf.Variable(tf.random_normal([2,6],stddev=1))w2=tf.Variable(tf.random_normal([6,1],stddev=1))x=tf.placeholder(dtype=tf.float32,shape=(4,2),name="input")h=tf.matmul(x,w1)y=tf.matmul(h,w2)init_op=tf…
>>> 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)>>&…
>>> import tensorflow as tf>>> node1 = tf.constant(3.0, dtype=tf.float32)>>> node2 = tf.constant(4.0)>>> node3=tf.constant(66)>>> print(node1,node2,node3)(<tf.Tensor 'Const:0' shape=() dtype=float32>, <…