Python 比较张量元张量流
如果我有x=[0,10],并且我想做如下事情,那么TF中的等效操作是什么Python 比较张量元张量流,python,tensorflow,Python,Tensorflow,如果我有x=[0,10],并且我想做如下事情,那么TF中的等效操作是什么 assert x[1] > x[0] 我尝试了以下方法: tf.debugging.assert_greater(x[1], x[0], message=f"{x[1]} has to be greater than {x[0]}" ) 当我有x=tf.constant([10,0])时,它没有抛出任何错误。 谢谢 您没有正确理解tf.debug.assert\
assert x[1] > x[0]
我尝试了以下方法:
tf.debugging.assert_greater(x[1], x[0],
message=f"{x[1]} has to be greater than {x[0]}"
)
当我有x=tf.constant([10,0])时,它没有抛出任何错误。
谢谢 您没有正确理解
tf.debug.assert\u morer
。看看下面的例子。如果a>b
,它将什么也不做,但是如果a
,它将抛出一个错误,因此它会反过来
import numpy as np
import tensorflow as tf
tf.debugging.assert_greater(0, 1,message=f"{x[1]} has to be greater than {x[0]}")
----
InvalidArgumentError: 0 has to be greater than 10
Condition x > y did not hold.
First 1 elements of x:
[0]
First 1 elements of y:
[1]
这回答了你的问题吗?我不这么认为。我需要比较一个张量中的元素,而不是比较两个张量
import numpy as np
import tensorflow as tf
tf.debugging.assert_greater(1, 0,message=f"{x[1]} has to be greater than {x[0]}")
----
nothing