问题
I know there is tf.greater(x,y)
which will return true if x > y (element-wise). Is there a function that returns true if lower_bound < x < upper_bound (element-wise) for a tensor x?
回答1:
There's not a specific function for that, but you can use a combination of tf.greater
, tf.less
, and tf.logical_and
to get the same result.
lower_tensor = tf.greater(x, lower)
upper_tensor = tf.less(x, upper)
in_range = tf.logical_and(lower_tensor, upper_tensor)
来源:https://stackoverflow.com/questions/55870502/tensorflow-function-to-check-whether-a-value-is-in-given-range