gpt4 book ai didi

python - 如何比较 tensorflow 中的张量?

转载 作者:太空宇宙 更新时间:2023-11-03 14:57:47 24 4
gpt4 key购买 nike

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

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

temp_tensor = a_placeholder > 0

然后例如,在 nn_ops.py

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

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

最佳答案

考虑到 tf.equal(temp1, temp2) 返回张量(例如 [[True], [False]])它是如果你想找到一个答案“这个张量是否等于另一个张量”并且你不想比较元素,那将毫无用处。你可能想要的是

if sess.run(tf.reduce_all(tf.equal(temp1, temp2))):
print('temp1 is equal temp2')
else:
print('temp1 is not equal temp2')

关于python - 如何比较 tensorflow 中的张量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41117586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com