TypeError: 'Tensor' object cannot be interpreted as an integer
Not really sure what you want to achieve here. loop
is a tf.Tensor
and range
expects an integer
as argument, hence the error. If you just want to print a
5 times, why don't you just set loop to the numerical value of 5?
Otherwise, the following code should work, as loop.eval()
returns the value of loop
which is 5:
a = tf.Variable([1,2,3,4,5],dtype = tf.int32)
loop = tf.size(a)
....
for i in range(loop.eval()):
print(sess.run(a))
If you don't want to execute the TF graph multiple times, take a look at tf.while_loop.
tf.size()
does not give you a value or list.
a = tf.Variable([1,2,3,4,5],dtype = tf.int32)
v = a.get_shape()
loop = v.num_elements()
...
Perhaps, try this.