Having a Tensor of strings of numbers (like "32", "45" and so on), how could I convert it to a tensor that has a symbol repeated as much times as the number indicates.
For instance, if I have a Tensor ["2", "3", "0", "1"], I would like to obtain something like ["aa", "aaa", "", "a"].
I have obtained it using numpy, but now I'm trying to do it in TensorFlow directly because I don't have the session started, so I cannot look for the variable value.
I share here a snippet of the code
import tensorflow as tf
a = tf.Variable(["2", "3", "0", "1"], dtype=tf.dtypes.string)
res = tf.strings.regex_replace(a, "([0-9]+)", r"a" * int("\\1"))
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(sess.run(res)) # It should show ["aa", "aaa", "", "a"]
But int("\1") doesn't return the number, but a ValueError:
ValueError: invalid literal for int() with base 10: '\1'