我想计算大于固定阈值(这里是0.8)的元素的平均值.
麻木中的任务:
X = np.array([[0.11,0.99,0.70]])
print(np.nanmean(X[X>0.8]))
Out : 0.99
在不将张量c
转换为数值数组的情况下,TensorFlow中的类似功能是什么?
示例:
c = tf.constant([[0.11,0.99,0.70]])
tf.reduce_mean(tf.where(tf.greater(c,(tf.constant(0.8, dtype=tf.float32)))))
输出等于0!
Output : <tf.Tensor: shape=(), dtype=int64, numpy=0>