My ultimate goal is to judge placeholder value.
Now I can judge a placeholder by using the regular python comparison expressions. Then, you know, it returns a tensor.
temp_tensor = a_placeholder > 0
Then for example , in nn_ops.py
temp1 = constant_op.constant(True)
temp2 = constant_op.constant(False)
how to compare temp1 and temp2? Or whether temp1 and temp2 are equal.
We can compare two tensors by using the torch. eq() method. This method compares the corresponding elements of tensors. It has to return rue at each location where both tensors have equal value else it will return false.
The easiest[A] way to evaluate the actual value of a Tensor object is to pass it to the Session. run() method, or call Tensor. eval() when you have a default session (i.e. in a with tf. Session(): block, or see below).
To check if two tensors are equal, one can use tf. equal .
add() Function. The tf. add() function returns the addition of two tf. Tensor objects element wise.
Considering that tf.equal(temp1, temp2) returns tensor (e.g. [[True], [False]]) it is 
usefulless if you want to find an answer "is this tensor equal to another tensor", and you don't want compare elements.
What you might want is 
if sess.run(tf.reduce_all(tf.equal(temp1, temp2))):
    print('temp1 is equal temp2') 
else:
    print('temp1 is not equal temp2') 
                        You should use the tf.equal function. Following the official docs, tf.equal() accepts two tensors and does the operation element wise. Something like this should work,
result = tf.equal(temp1, temp2)
Note, result will have the same dimension as temp1 and temp2 and filled with boolean values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With