Hope it helps!
I think you need to get some fundamentals right. With the examples above you have created tensors (multi dimensional array). But for tensor flow to really work you have to initiate a "session" and run your "operation" in the session. Notice the word "session" and "operation". You need to know 4 things to work with tensorflow:
Now from what you wrote out you have given the tensor, and the operation but you have no session running nor a graph. Tensor (edges of the graph) flow through graphs and are manipulated by operations (nodes of the graph). There is default graph but you can initiate yours in a session.
When you say print , you only access the shape of the variable or constant you defined.
So you can see what you are missing :
with tf.Session() as sess:
print(sess.run(product))
print (product.eval())
Hope it helps!
run
or eval
) is to use the Print
operation as in this example:# Initialize session import tensorflow as tf sess = tf.InteractiveSession() # Some tensor we want to print the value of a = tf.constant([1.0, 3.0]) # Add print operation a = tf.Print(a, [a], message="This is a: ") # Add more elements of the graph using a b = tf.add(a, a)
b.eval()
, we get:I tensorflow/core/kernels/logging_ops.cc:79] This is a: [1 3]
Reiterating what others said, its not possible to check the values without running the graph.
A simple snippet for anyone looking for an easy example to print values is as below. The code can be executed without any modification in ipython notebook
import tensorflow as tf
#define a variable to hold normal random values
normal_rv = tf.Variable( tf.truncated_normal([2,3],stddev = 0.1))
#initialize the variable
init_op = tf.initialize_all_variables()
#run the graph
with tf.Session() as sess:
sess.run(init_op) #execute init_op
#print the random values that we sample
print (sess.run(normal_rv))
Output:
[[-0.16702934 0.07173464 -0.04512421]
[-0.02265321 0.06509651 -0.01419079]]