title: Computing inverse of a Tensor using tf.map_fn
body: <p>Using Tensorflow 1.4 I want to compute elementwise inverse (x --> 1/x) of a tensor using map functions. If the value of an element in the Tensor is zero, I want to have zero output.</p>
  
  <p>As an example for the <code>tensor: [[0, 1, 0], [0.5, 0.5, 0.3]]</code>, I want to have the <code>output: [[0,1,0], [2, 2, 3.333]]</code>.
  I know that I can easily get the desired output using tf.math.reciprocal_no_nan() in <code>tf2.0</code> and <code>tf.math.divide_no_nan()</code> in <code>tf 1.4</code>, but I am wondering why the following code does not work:</p>
  
  <pre><code>tensor = tf.constant([[0, 1, 0], [0.5, 0.5, 0.3]], tf.float32)
  tensor_inverse = tf.map_fn(lambda x: tf.cond(tf.math.not_equal(x, 0.0), lambda x: 1/x, lambda: 0) , tensor)
  </code></pre>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()</p>
  </blockquote>