Count number of “True” values in boolean Tensor

后端 未结 4 1400
粉色の甜心
粉色の甜心 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:47

    You can cast the values to floats and compute the sum on them: tf.reduce_sum(tf.cast(myOtherTensor, tf.float32))

    Depending on your actual use case you can also compute sums per row/column if you specify the reduce dimensions of the call.

提交回复
热议问题