如果条件是一个标量,但t和e是相等形状的张量,那我该怎么办tf.select(condition, t, e)
?TensorFlow希望条件与t和e相同。
tf.select()
现在称为前op tf.where()
(在TensorFlow 1.0中)。该tf.where()
运算对的形状的略奇条件condition
:它可以具有来自两个分支的不同的形状,但只有当它是一个矢量,其长度尺寸为第0尺寸相同t
和e
。因此,您可以使程序按以下方式工作:
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)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句