title: Tensorflow: How to convert NaNs to a number?
body: <p>I'm trying to calculate the entropy of the weights while training my graph and to use it for regularization. This of course involves <code>w*tf.log(w)</code>, and as my weights are changing some of them are bound to get into a region which results in NaNs being returned.</p>
  
  <p>Ideally I would include a line in my graph setup:</p>
  
  <pre><code>w[tf.is_nan(w)] = &lt;number&gt;
  </code></pre>
  
  <p>but tensorflow doesn't support assigning like that. I could of course create an operation, but that wouldn't work because I need for it to happen during the execution of the entire graph. I can't wait for the graph to execute and then 'fix' my weights, is has to be part of the graph execution.</p>
  
  <p>I haven't been able to find an equivalent to <code>np.nan_to_num</code> in the docs.</p>
  
  <p>Anybody have an idea?</p>
  
  <p>(For obvious reasons, adding an epsilon doesn't work)</p>