Saturday, 5 May 2018

tensorflow first program

import tensorflow as tf
m1 = tf.constant([[3,3]])
print(m1)
m2 = tf.constant([[2],[3]])
prod = tf.matmul(m1,m2)
print(prod)

sess = tf.Session()
result = sess.run(prod)
result1 = sess.run(m1)
result2 = sess.run(m2)
print(result)
print(result1)
print(result2)

sess.close()


==>>
[[15]]
[[3 3]]
[[2]
 [3]]

----------------------------

variable:

import tensorflow as tf
x = tf.Variable([1,2]);
a = tf.constant([3,3,]);
sub = tf.subtract(x,a);
add = tf.add(x, sub)
init = tf.global_variables_initializer()
with tf.Session() as sess:
    sess.run(init)
    print(sess.run(sub))
    print(sess.run(add))
    

===>


[-2 -1]
[-1  1]

No comments:

Post a comment