I want to do something like this.
Let's say we have a tensor A.
A = [[1,0],[0,4]]
And I want to get nonzero values and their indices from it.
Nonzero values: [1,4]
Nonzero indices: [[0,0],[1,1]]
There are similar operations in Numpy.np.flatnonzero(A)
return indices that are non-zero in the flattened A.x.ravel()[np.flatnonzero(x)]
extract elements according to non-zero indices.
Here's a link for these operations.
How can I do somthing like above Numpy operations in Tensorflow with python?
(Whether a matrix is flattened or not doesn't really matter.)