Import TensorFlow:
In [1]:
import tensorflow as tf
Start with a 1x2 matrix:
In [2]:
x = tf.constant([[1, 2]])
Let's negate it. Define the negation op to be run on the matrix:
In [4]:
neg_x = tf.negative(x)
It's nothing special if you print it out. In fact, it doesn't even perform the negation computation. Check out what happens when you simply print it:
In [16]:
print(neg_x)
You need to summon a session so you can launch the negation op:
In [17]:
with tf.Session() as sess:
result = sess.run(neg_x)
print(result)