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.
Asked
Active
Viewed 1,374 times
0
-
1http://stackoverflow.com/questions/36612512/tensorflow-how-to-get-a-tensor-by-name – agent_bean Jan 30 '17 at 21:16
-
1http://stackoverflow.com/questions/34097281/how-can-i-convert-a-tensor-into-a-numpy-array-in-tensorflow – agent_bean Jan 30 '17 at 21:21
1 Answers
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