title: How to implement indicator function in tensorflow?
body: <p>I wanna implement a function like this:if x == k, f(x) = 1, else f(x) = 0(k is a parameter). So I used tf.equal and tf.cast and my code was like this:</p>
  
  <pre class="lang-py prettyprint-override"><code>import tensorflow as tf
  
  a = range(12)
  a = tf.Variable(a)
  b = 6
  b = tf.Variable(b)
  a = tf.reshape(a, [3, 4])
  
  sess = tf.Session()
  
  init = tf.global_variables_initializer()
  sess.run(init)
  c = tf.equal(a, b)
  d = tf.cast(c, tf.int32)
  print sess.run(c)
  print sess.run(d)
  </code></pre>
  
  <p>It seems fine, <strong>but the problem is tf.gradients(d, a) and tf.gradients(d, b) are None.</strong> I tried tf.gradients(c, a) and got TypedError. Are there any decent way to implement this function?</p>