I wrote some code that iterates over the shape of my tensor and adds a value to tensor in each step. The problem is it is slow for a large number of iterations (and I need a lot of them):
for i in range(0, num_samples):
for j in range(0, int(numTimeSteps.numpy())):
random_num = tf.squeeze(tf.random.normal([1], mean, std_dev, dtype=dtype))
tensor[i,j].assign(tf.math.add(random_num, estr[i,j]).numpy())
In each iteration I add a random number (drawn from a normal distribution) to the tensor
- num_samples is specified by the user and can be in the range of 1000-100.000
- numTimeSpes is 80
Is there a way to optimize this?