Ch 02: Concept 02

Evaluating ops

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]:

Tensor("Neg_3:0", shape=(1, 2), dtype=int32)

You need to summon a session so you can launch the negation op:

In [17]:
with tf.Session() as sess:
    result =

[[-1 -2]]