In TensorFlow, I can get the count of each element in an array with tf.bincount:
x = tf.placeholder(tf.int32, [None])
freq = tf.bincount(x)
tf.Session().run(freq, feed_dict = {x:[2,3,1,3,7]})
this returns
Out[45]: array([0, 1, 1, 2, 0, 0, 0, 1], dtype=int32)
Is there a way to do this on a 2D tensor? i.e.
x = tf.placeholder(tf.int32, [None, None])
freq = tf.axis_bincount(x, axis = 1)
tf.Session().run(freq, feed_dict = {x:[[2,3,1,3,7],[1,1,2,2,3]]})
that returns
[[0, 1, 1, 2, 0, 0, 0, 1],[0, 2, 2, 1, 0, 0, 0, 0]]