Use tf.gather_nd
or tf.boolean_mask
:
import tensorflow as tf
t2 = tf.constant([[0, 11, 2, 3, 4],
[5, 61, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19]])
valid_mask = t2 <= 10
validIndex = tf.where(valid_mask)
print(tf.gather_nd(t2, indices=validIndex))
print(tf.boolean_mask(t2, valid_mask))
tf.Tensor([ 0 2 3 4 5 7 8 9 10], shape=(9,), dtype=int32)
tf.Tensor([ 0 2 3 4 5 7 8 9 10], shape=(9,), dtype=int32)
顺便说一句,根据您的情况,您的预期出局数应包括数字 10。