As in the question, I am trying to remove all vectors of zeros (ie [0, 0, 0, 0]
) from the tensor.
Considering:
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 tried the following code (inspired by this ):
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 it bool_mask
also has the form (10000, 4), as if he were comparing each element of the tensor x
with zero, not a row.
I was thinking about using tf.reduce_sum
where the whole string is zero, but this also omits the type strings [1, -1, 0, 0]
, and I don't want this.
Ideas?