0

There are ways to initialize tensor with a numpy array. But is there any way to do the opposite. Meaning initialize a numpy array with a tensor in the graph.

user3102085
  • 459
  • 3
  • 8
  • 19

1 Answers1

1

You have to evaluate the tensor under a session. Assume you have a tensor t defined as

x = tf.Variable(...)
y = tf.Variable(...)

t = tf.add(x, y)

and you want to know its value (given the current x and y). You then just use a session to fetch it:

with tf.Session() as sess:
    numpy_array = sess.run(t)

or, equivalently,

with tf.Session() as sess:
    numpy_array = t.eval(sess)

That should be all there is to it.

sunside
  • 8,069
  • 9
  • 51
  • 74