Reputation: 115
I wanted to use the tf.where
function in tensorflow.
selected_data = tf.where(mask,some_place_holder,zeros)
however, when I wrote
zeros = tf.zeros(some_place_holder.shape)
error occurs:
ValueError: Cannot convert a partially known TensorShape to a Tensor: (?, 1000, 10)
I also tried to use tf.fill
, but similar errors occured.
Well, there indeed some solution such as
zeros = tf.matmul(some_place_holder , tf.zeros([some_place_holder.shape[-1],some_place_holder.shape[-1]]))
but is there any better solution?
Upvotes: 0
Views: 1057
Reputation: 214927
You can use tf.zeros_like(some_place_holder)
:
input_tensor = tf.placeholder(tf.int8, shape=[None, 3])
zeros = tf.zeros_like(input_tensor)
with tf.Session() as sess:
print(sess.run(zeros, feed_dict={input_tensor: [[1,2,3]]}))
# [[0 0 0]]
Upvotes: 2