I would like to modify certain indexes of a Variable inside a while loop. Basically convert the python code below to Tensorflow:
import numpy
tf_variable=numpy.zeros(10,numpy.int32)
for i in range (10):
tf_variable[i]=i
tf_variable
Tensorflow code would look like following: except it gives error
import tensorflow as tf
var=tf.get_variable('var',initializer=tf.zeros([10],tf.int32),trainable=False)
itr=tf.constant(0)
sess=tf.Session()
sess.run(tf.global_variables_initializer()) #initializing variables
print('itr=',sess.run(itr))
def w_c(itr,var):
return(tf.less(itr,10))
def w_b(itr,var):
var=tf.assign(var[1],9) #lets say i want to modify index 1 of variable var
itr=tf.add(itr,1)
return [itr,var] #these tensors when returning actually get called
OP=tf.while_loop(w_c,w_b,[itr,var],parallel_iterations=1,back_prop=False)
print(sess.run(OP))
Thanks