How to remove row of array which row contain value less than 11
How to remove row of array which row contain value less than 11
Following example is in ordinary Python code. But how to do it in Tensorflow library? I want to remove row of array which row contain value less than 11. I want this coding to calculate accuracy for good prediction only.
a = np.array([[ 0, 1, 2, 0, 4, 5, 6, 7, 8, 10],
[ 0, 11, 0, 13, 0, 15, 0, 17, 18, 0]])
print (a[a.max(axis=1) >= 11])
1 Answer
1
Use tf.reduce_max
to calculate the maximum value along an axis, and tf.boolean_mask
to subset the tensor based on the boolean condition:
tf.reduce_max
tf.boolean_mask
import tensorflow as tf
tf.InteractiveSession()
t = tf.constant(a)
t1 = tf.boolean_mask(t, tf.reduce_max(t, axis=1) >= 11)
t1.eval()
# array([[ 0, 11, 0, 13, 0, 15, 0, 17, 18, 0]])
logits_filtered = tf.boolean_mask(logits, tf.reduce_max(logits, axis=1) >= acc_filtered_r_)
ValueError: Number of mask dimensions must be specified, even if some dimensions are None. E.g. shape=[None] is ok, but shape=None is not.– Quanter
Aug 22 at 13:57
logits_filtered = tf.boolean_mask(logits, tf.reduce_max(logits, axis=1) >= acc_filtered_r_)
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
From tensorflow: "IMPORTANT: PLEASE ADD THE LANGUAGE TAG YOU ARE DEVELOPING IN. TENSORFLOW SUPPORTS MORE THAN ONE LANGUAGE."
– user202729
Aug 18 at 15:04