本文介绍了如何比较张量流中的张量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的最终目标是判断placeholder的值.

My ultimate goal is to judge placeholder value.

现在我可以使用常规的python比较表达式来判断一个placeholder.然后,你知道,它返回一个张量.

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

然后例如,在nn_ops.py

temp1 = constant_op.constant(True)
temp2 = constant_op.constant(False)

如何比较temp1temp2?或者 temp1temp2 是否相等.

how to compare temp1 and temp2? Or whether temp1 and temp2 are equal.

推荐答案

考虑到 tf.equal(temp1, temp2) 返回张量(例如 [[True], [False]]) 是如果您想找到这个张量是否等于另一个张量"的答案,并且您不想要比较元素,则没有用.你可能想要的是

Considering that tf.equal(temp1, temp2) returns tensor (e.g. [[True], [False]]) it isusefulless 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')

这篇关于如何比较张量流中的张量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 15:03