1

I need to save some values to specific places in a tensorflow array:

import tensorflow as tf
import numpy as np

AVG = tf.Variable([0, 0, 0, 0, 0], name='data')

for i in range(5): 
   data = np.random.randint(1000, size=10000)
   AVG += np.average(data)     

I need to make it average each iteration in different places of the AVG variable. Is this doable ?

1 Answer 1

1

You can use tf.scatter_add. Here is a complete working program :

import tensorflow as tf
import numpy as np

AVG = tf.Variable([0, 0, 0, 0, 0], name='data')

for i in range(5):
  data = np.random.randint(1000, size=10000)
  AVG = tf.scatter_add(AVG, [i], [np.average(data).astype('int')])

sess = tf.InteractiveSession()
sess.run(tf.initialize_all_variables())
print(AVG.eval())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.