My idea is that we get unique numbers and their number. Then we find the numbers that appear most often. Finally, we get these numbers (there can be more than one) using their indices in the tensor of the number counter.
samples = tf.constant([10, 32, 10, 5, 7, 9, 9, 9]) unique, _, count = tf.unique_with_counts(samples) max_occurrences = tf.reduce_max(count) max_cond = tf.equal(count, max_occurrences) max_numbers = tf.squeeze(tf.gather(unique, tf.where(max_cond))) with tf.Session() as sess: print 'Most frequent Numbers\n', sess.run(max_numbers) > Most frequent Numbers 9
source share