Just like the question says, I'm trying to remove all zeros vectors (i.e [0, 0, 0, 0]
) from a tensor.
Given:
array([[ 0. , 0. , 0. , 0. ],
[ 0.19999981, 0.5 , 0. , 0. ],
[ 0.4000001 , 0.29999995, 0.10000002, 0. ],
...,
[-0.5999999 , 0. , -0.0999999 , -0.20000005],
[-0.29999971, -0.4000001 , -0.30000019, -0.5 ],
[ 0. , 0. , 0. , 0. ]], dtype=float32)
I had tried the following code (inspired by this SO):
x = tf.placeholder(tf.float32, shape=(10000, 4))
zeros_vector = tf.zeros(shape=(1, 4), dtype=tf.float32)
bool_mask = tf.not_equal(x, zero_vector)
omit_zeros = tf.boolean_mask(x, bool_mask)
But bool_mask
seem also to be of shape (10000, 4), like it was comparing every element in the x
tensor to zero, and not rows.
I thought about using tf.reduce_sum
where an entire row is zero, but that will omit also rows like [1, -1, 0, 0]
and I don't want that.
Ideas?