Try:
ones = tf.ones_like(x) # create a tensor all ones
mask = tf.greater(x, ones) # boolean tensor, mask[i] = True iff x[i] > 1
slice_y_greater_than_one = tf.boolean_mask(y, mask)
See tf.boolean_mask
EDIT: another (better ?) way to do it:
import tensorflow as tf
x = tf.constant([1, 2, 0, 4])
y = tf.Variable([1, 2, 0, 4])
mask = x > 1
slice_y_greater_than_one = tf.boolean_mask(y, mask)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print (sess.run(slice_y_greater_than_one)) # [2 4]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…