2016-08-21 106 views

回答

1

前者tf.select()运现在被称为tf.where()(在TensorFlow 1.0)。 tf.where() op在condition的形状上有一个稍微奇怪的情况:它可以具有与两个分支不同的形状,但只有它的长度与te的第0维尺寸相同的向量才具有不同的形状。因此,你可以使你的程序工作如下:

condition = ... # scalar 
t = ...   # shape = [4, 9, 2] 
e = ...   # shape = [4, 9, 2] 

# Tile `condition` as a vector whose length matches the 0th dimension of `t`. 
condition_vector = tf.tile([condition], [tf.shape(t)[0]]) 

result = tf.where(condition_vector, t, e) 
1

您可以使用tf.tile使条件相同的形状t

+0

你能解释一下吗?假设条件是一个标量占位符或变量,并且t和e具有形状(4,9,2)。 –