Count number of “True” values in boolean Tensor

后端 未结 4 1394
粉色の甜心
粉色の甜心 2020-12-29 01:58

I understand that tf.where will return the locations of True values, so that I could use the result\'s shape[0] to get the number of <

4条回答
  •  失恋的感觉
    2020-12-29 02:52

    I think this is the easiest way to do it:

    In [38]: myOtherTensor = tf.constant([[True, True], [False, True]])
    
    In [39]: if_true = tf.count_nonzero(myOtherTensor)
    
    In [40]: sess.run(if_true)
    Out[40]: 3
    

提交回复
热议问题