If statement 在tensorflow中编写if语句并比较两个张量的值

If statement 在tensorflow中编写if语句并比较两个张量的值,if-statement,boolean,tensorflow,If Statement,Boolean,Tensorflow,我有以下情况: if tf.shape(n_spec)[0] < tf.shape(s_spec)[0]: n_spec = tf.concat(0, [tf.zeros([empty_cols, n_spec.get_shape()[1]], tf.int32), n_spec]) 如何重新格式化上述内容?从您的代码来看,n\u spec的形状似乎是静态已知的(因为您使用的是n\u spec.get\u shape())。在这种情况下,您可以简单地执行以下操作: if n_s

我有以下情况:

if tf.shape(n_spec)[0] < tf.shape(s_spec)[0]:
    n_spec = tf.concat(0, [tf.zeros([empty_cols, n_spec.get_shape()[1]], tf.int32), n_spec]) 

如何重新格式化上述内容?

从您的代码来看,
n\u spec
的形状似乎是静态已知的(因为您使用的是
n\u spec.get\u shape()
)。在这种情况下,您可以简单地执行以下操作:

if n_spec.get_shape()[0] < s_spec.get_shape()[0]:
  n_spec = tf.concat(0, [tf.zeros([empty_cols, n_spec.get_shape()[1]], tf.int32), n_spec])
如果n_spec.get_shape()[0]
if n_spec.get_shape()[0] < s_spec.get_shape()[0]:
  n_spec = tf.concat(0, [tf.zeros([empty_cols, n_spec.get_shape()[1]], tf.int32), n_spec])