TensorFlow 2.0
Swift execution is enabled by default, so just call .numpy() on the Tensor object.
import tensorflow as tf a = tf.constant([[1, 2], [3, 4]]) b = tf.add(a, 1) tf.multiply(a, b). numpy()
Itโs worth noting (from the documents),
A Numpy array can share memory with a Tensor object. Any changes in one can be reflected in another.
Bold accent mine. A copy may or may not be returned, and this is an implementation detail.
If Eager Execution is disabled, you can plot it and then run it through tf.compat.v1.Session :
a = tf.constant([[1, 2], [3, 4]]) b = tf.add(a, 1) out = tf.multiply(a, b) out.eval(session=tf.compat.v1.Session()) # array([[ 2, 6], # [12, 20]], dtype=int32)
See Also TF 2.0 Character Map for mapping the old API to the new.
cs95 Jun 12 '19 at 4:50 2019-06-12 04:50
source share