1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| import tensorflow as tf
sess = tf.InteractiveSession()
I_matrix = tf.eye(5)
X = tf.Variable(tf.eye(10),name='helloX') X.initializer.run()
A = tf.Variable(tf.random_uniform([5,10]),name='helloA') A.initializer.run()
product = tf.matmul(A,X)
b = tf.Variable(tf.random_uniform([5,10],0,2,dtype=tf.int32),name='hellob') b.initializer.run()
b_new = tf.cast(b,dtype=tf.float32)
t_sum = tf.add(product,b_new) t_sub = product - b_new
sess.close()
a = tf.Variable(tf.random_uniform([4,5],1,10,dtype=tf.int32)) b = tf.Variable(tf.random_uniform([4,5],1,10,dtype=tf.int32))
A = a * b
B = tf.scalar_mul(2,A)
C = tf.div(a,b)
D = tf.mod(a,b)
init_op = tf.global_variables_initializer()
with tf.Session() as sess: sess.run(init_op) writer = tf.summary.FileWriter('graphs',sess.graph) a,b,A_R,B_R,C_R,D_R = sess.run([a,b,A,B,C,D]) print("============= a =============\n",a, "\n============= b =============\n",b, "\n============ a*b ============\n",A_R, "\n=========== 2*a*b ===========\n",B_R, "\n============ a/b ============\n",C_R, "\n============ a%b ============\n",D_R)
writer.close()
|