In TensorFlow, how can I get nonzero values and their indices from a tensor with python?

前端 未结 2 1110
花落未央
花落未央 2021-02-03 23:08

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 fro

2条回答
  •  悲哀的现实
    2021-02-03 23:27

    #assume that an array has 0, 3.069711,  3.167817.
    mask = tf.greater(array, 0)
    non_zero_array = tf.boolean_mask(array, mask)
    

提交回复
热议问题