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 <
There is a tensorflow function to count non-zero values tf.count_nonzero. The function also accepts an axis
and keep_dims
arguments.
Here is a simple example:
import numpy as np
import tensorflow as tf
a = tf.constant(np.random.random(100))
with tf.Session() as sess:
print(sess.run(tf.count_nonzero(tf.greater(a, 0.5))))