Suppose I have an array: input = np.array([[1,0,3,5,0,8,6]]) and I want to filter out [1,3,5,8,6] .
I know that you can use tf.where with a condition, but the return value still has 0. Output of the next fragment [[[1 0 3 5 0 8 6]]] . I also don't understand why tf.where needed for both x and y .
In any case, can I get rid of 0 in the resulting tensor?
import numpy as np import tensorflow as tf input = np.array([[1,0,3,5,0,8,6]]) X = tf.placeholder(tf.int32,[None,7]) zeros = tf.zeros_like(X) index = tf.not_equal(X,zeros) loc = tf.where(index,x=X,y=X) with tf.Session() as sess: out = sess.run([loc],feed_dict={X:input}) print np.array(out)
source share