<p>我知道<code>tf.where</code>将返回<code>True</code>值的位置,这样我就可以使用结果的<code>shape[0]</code>来获得<code>True</code>的数量</p>
<p>但是,当我尝试使用它时,维度是未知的(这是有意义的,因为它需要在运行时计算)。所以我的问题是,我怎样才能访问一个维度,并在一个操作中像求和一样使用它?</p>
<p>例如:</p>
<pre><code>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.
</code></pre>