2016-08-21 63 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)。 –

相關問題