Skip to content
Advertisement

Drop a row in a tensor if the sum of the elements is lower than some threshold

How can I drop rows in a tensor if the sum of the elements in each row is lower than the threshold -1? For example:

JavaScript

Since the sum of the last row is smaller than -1, I need to remove it and get the tensor (2, 3):

JavaScript

I know how to use tf.reduce_sum, but I do not know how to delete rows from a tensor. Something like df.drop would be nice.

Advertisement

Answer

tf.boolean_mask is all you need.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement