title: Tensorflow - Can't convert Operation to Tensor
body: <p>
  I would like to compute the pairwise Euclidean distance between the output of an Operation and a Tensor. I'm using code suggested <a href="https://stackoverflow.com/questions/43839120/compute-the-pairwise-distance-between-each-pair-of-the-two-collections-of-inputs">here</a>. Here's the gist of my code:</p>
  
  <pre><code>    # Suppose logits has shape [32, 128]
      logits = tf.get_default_graph().get_operation_by_name('Tanh')
      y = tf.placeholder(tf.float32, shape=[10, 128])
  
      m1, m2, k = 32, tf.shape(y)[0], latent_dim
  
      # Get the pairwise distances
      p1 = tf.matmul(tf.expand_dims(tf.reduce_sum(tf.square(logits), 1), 1),
                    tf.ones(shape=(1, m2)))
      p2 = tf.transpose(tf.matmul(
          tf.reshape(tf.reduce_sum(tf.square(y), 1), shape=[-1, 1]),
          tf.ones(shape=(m1, 1)),
          transpose_b=True
      ))
      distance_predictions = tf.sqrt(tf.add(p1, p2) - 2 * 
           tf.matmul(logits, y, transpose_b=True))        
  </code></pre>
  
  
  
  <p>However I get the following error:</p>
  
  <pre><code>TypeError: Can't convert Operation '.../Tanh' to Tensor (target dtype=None, name=u'x', as_ref=False)
  </code></pre>
  
  <p>For this line:</p>
  
  <pre><code>p1 = tf.matmul(tf.expand_dims(tf.reduce_sum(tf.square(logits), 1), 1),
                tf.ones(shape=(1, m2)))
  </code></pre>
  
  <p>How should I fix this?
  </p>