tensorflow
tensor
printing
full-tensor
guide

How to print full not truncated tensor in tensorflow?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

TensorFlow truncates large tensors by default so console output stays readable. If you really need every element for debugging, the TensorFlow-native answer is to use tf.print with summarize=-1, which tells TensorFlow to print the full tensor instead of shortening it.

Use tf.print(..., summarize=-1)

The TensorFlow API documents that summarize=-1 prints all elements:

python
1import tensorflow as tf
2
3x = tf.reshape(tf.range(24), (4, 6))
4tf.print(x, summarize=-1)

Without summarize=-1, TensorFlow typically prints only the first and last few entries from each dimension.

Prefer tf.print Inside TensorFlow Functions

When code runs inside tf.function, tf.print is the correct debugging tool:

python
1import tensorflow as tf
2
3@tf.function
4def debug_tensor(x):
5    tf.print("full tensor:", x, summarize=-1)
6    return x * 2
7
8debug_tensor(tf.reshape(tf.range(12), (3, 4)))

Ordinary Python print is not a reliable substitute inside traced TensorFlow execution.

Use NumPy Printing in Eager Mode

If you are debugging eagerly and just want to inspect the tensor value as an array, converting to NumPy can also work:

python
1import numpy as np
2import tensorflow as tf
3
4np.set_printoptions(threshold=np.inf)
5
6x = tf.reshape(tf.range(24), (4, 6))
7print(x.numpy())

This is convenient in notebooks, but it is a Python-side representation rather than TensorFlow’s own printing path.

Send Output Somewhere More Useful

tf.print can do more than print to the default console stream. For long debugging sessions, it is often easier to direct output to a file or another stream so notebook output stays readable:

python
1import tensorflow as tf
2
3x = tf.reshape(tf.range(12), (3, 4))
4tf.print("tensor dump:", x, summarize=-1, output_stream="file://tensor.log")

That gives you the full tensor without overwhelming the interactive session.

If you are inspecting only one problematic slice, combine full printing with targeted indexing so the debug signal stays manageable:

python
tf.print("row 0:", x[0], summarize=-1)

That approach often answers the real debugging question faster than dumping an entire large activation tensor every step.

It is also a good reminder that "print the full tensor" is a debugging tool, not a normal logging strategy for production or training output.

Most of the time, printing the shape, dtype, or one representative slice is enough. Reach for full output when the exact values themselves are the bug.

That keeps debugging targeted and output volume reasonable.

Be Careful in Notebooks and Loops

TensorFlow notes that tf.print writes to notebook cell output in environments such as Jupyter and Colab. That is useful, but printing a full tensor inside a training loop can flood the notebook and slow everything down.

If you only need to inspect one batch or one intermediate tensor, print once and remove the statement after debugging.

Common Pitfalls

The biggest mistake is using Python print inside tf.function and expecting it to behave like tf.print. The two tools operate differently.

Another issue is printing full tensors repeatedly inside loops, callbacks, or per-step debugging code. The output volume can become the real problem.

People also forget that NumPy print options affect NumPy arrays, not the behavior of tf.print.

Finally, if you only need shape information or a small slice, printing the entire tensor may be unnecessary. Full printing is useful, but it should be deliberate.

Summary

  • Use tf.print(tensor, summarize=-1) to print a full tensor without truncation.
  • Prefer tf.print over Python print inside tf.function.
  • In eager mode, converting to NumPy and using np.set_printoptions(threshold=np.inf) is another option.
  • Avoid printing huge tensors repeatedly inside loops or training code.
  • Print the full tensor only when every element is genuinely needed for debugging.

Course illustration
Course illustration

All Rights Reserved.