Home > Article > Backend Development > How do I convert a Tensorflow Tensor to a NumPy Array?
Convert a Tensor to Numpy Array in Tensorflow
In Tensorflow, converting a tensor into a numpy array is straightforward. Here's how:
<code class="python">import tensorflow as tf a = tf.constant([[1, 2], [3, 4]]) b = tf.add(a, 1) a_numpy = a.numpy() # Convert tensor 'a' to numpy array b_numpy = b.numpy() # Convert tensor 'b' to numpy array print(a_numpy) # [[1 2] # [3 4]] print(b_numpy) # [[2 3] # [4 5]]</code>
Notes:
The above is the detailed content of How do I convert a Tensorflow Tensor to a NumPy Array?. For more information, please follow other related articles on the PHP Chinese website!