# Tensorflow 2 – How to Print only the Value of a Tensor

This concise post shows you 2 ways to print only the value of a tensor in Tensorflow 2.

**Using the tf.print() function**

Example:

```
import tensorflow as tf
x = tf.constant([
[1, 2, 3],
[4, 5, 6]
])
tf.print(x)
```

Output:

```
[[1 2 3]
[4 5 6]]
```

Using the **print()** function will result in the following:

```
tf.Tensor(
[[1 2 3]
[4 5 6]], shape=(2, 3), dtype=int32)
```

Reference: https://www.tensorflow.org/api_docs/python/tf/print

**Using the numpy() method**

Example:

```
import tensorflow as tf
a = tf.constant([
[1, 1, 2, 3],
[5, 8, 13, 21]
])
print(a.numpy())
```

Output:

```
[[ 1 1 2 3]
[ 5 8 13 21]]
```

References: https://www.tensorflow.org/guide/tf_numpy

## Final Words

You’ve seen 2 examples of printing the value of a tensor object in Tensorflow 2. If you’d like to explore more basic stuff in machine learning and Python, take a look at the following posts:

- Tensorflow 2 – One Hot Encoding Examples
- Tensorflow 2 – Removing all Single Dimensions from a Tensor
- Tensorflow 2 – Changing the Datatype of a Tensor
- Most Popular Deep Learning Frameworks

You can also check out our Machine Learning category page or Python category page for more tutorials and examples.

Subscribe

0 Comments