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 True
s.
However, when I try and use this, the dimension is unknown (which makes sense as it needs to be computed at runtime). So my question is, how can I access a dimension and use it in an operation like a sum?
For example:
myOtherTensor = tf.constant([[True, True], [False, True]])
myTensor = tf.where(myOtherTensor)
myTensor.get_shape() #=> [None, 2]
sum = 0
sum += myTensor.get_shape().as_list()[0] # Well defined at runtime but considered None until then.
question from:
https://stackoverflow.com/questions/34598371/count-number-of-true-values-in-boolean-tensor 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…