To identify unique sequences, I need to use tensorflow functions to reduce a 2D int tensor to a 1D int tensor by concatenating the numbers in the last dimension.
For example,
[[1, 0], [2, 1], [1, 3], [2, 0], [0, 1]]
should become
[10, 21, 13, 20, 1]
What I have so far is
def reduce_concat(input):
def join(x):
dec = tf.range(0, x.shape[-1], 1)
dec = tf.map_fn(lambda x: tf.math.pow(10, x), dec)
return tf.math.reduce_sum(x * dec)
return tf.map_fn(join, input)
This almost works, but it ignores zeroes and is not very elegant.
I would be grateful if anyone could provide an elegant solution for this problem - thanks.