In TensorFlow, how can I get nonzero values and their indices from a tensor with python? : <p>I want to do something like this.<br>
Let's say we have a tensor A.  </p>

<pre><code>A = [[1,0],[0,4]]
</code></pre>

<p>And I want to get nonzero values and their indices from it.  </p>

<pre><code>Nonzero values: [1,4]  
Nonzero indices: [[0,0],[1,1]]
</code></pre>

<p>There are similar operations in Numpy.<br>
<code>np.flatnonzero(A)</code> return indices that are non-zero in the flattened A.<br>
<code>x.ravel()[np.flatnonzero(x)]</code> extract elements according to non-zero indices.<br>
Here's <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.flatnonzero.html" rel="noreferrer">a link</a> for these operations.</p>

<p>How can I do somthing like above Numpy operations in Tensorflow with python?<br>
(Whether a matrix is flattened or not doesn't really matter.)</p>
