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])





From tensorflow: "IMPORTANT: PLEASE ADD THE LANGUAGE TAG YOU ARE DEVELOPING IN. TENSORFLOW SUPPORTS MORE THAN ONE LANGUAGE."
– user202729
Aug 18 at 15:04




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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)