NumPy
array manipulation
full array display
Python
data truncation

How do I print the full NumPy array, without truncation?

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction

NumPy truncates large arrays when printing them so terminal output stays manageable. If you want to see the entire array, you need to change NumPy’s print options or render the array through a function that does not summarize it. The right approach depends on whether you want a one-off full print or a process-wide change.

Use np.set_printoptions for Global Behavior

The most direct solution is to set the print threshold high enough that NumPy stops abbreviating the array:

python
1import numpy as np
2
3arr = np.arange(100)
4np.set_printoptions(threshold=np.inf)
5
6print(arr)

Setting threshold=np.inf tells NumPy not to truncate based on element count.

This affects later array printing in the same process, so it is useful when you are debugging interactively and want full output repeatedly.

Use np.printoptions for a Temporary Scope

If you only want the change for one block of code, use the context manager form:

python
1import numpy as np
2
3arr = np.arange(100)
4
5with np.printoptions(threshold=np.inf):
6    print(arr)
7
8print(arr)  # default behavior restored

This is usually the cleaner option in scripts or notebooks because it avoids leaving global print settings changed for the rest of the session.

Control Line Wrapping Too

Sometimes the array is not truncated by threshold, but the output is still hard to read because of line wrapping. You can adjust linewidth as well:

python
with np.printoptions(threshold=np.inf, linewidth=200):
    print(np.arange(50))

That does not change whether elements are omitted. It only changes how wide NumPy lets each printed line become before wrapping.

Use array2string for Explicit String Rendering

If you want the full array as a string, np.array2string is useful:

python
1import numpy as np
2
3arr = np.arange(20).reshape(4, 5)
4text = np.array2string(arr, threshold=np.inf)
5print(text)

This is handy when you want to write the array to a log file, GUI text box, or another custom output destination instead of printing it directly.

Large Arrays Can Still Be Unpleasant to Read

Seeing the full array is not always the same as getting useful information from it. For very large arrays, printing the whole thing can flood the terminal or notebook output and make debugging harder.

In those cases, consider alternatives such as:

  • printing the shape
  • printing selected slices
  • using arr.min(), arr.max(), or summary statistics
  • saving to a file with np.savetxt

For example:

python
print(arr.shape)
print(arr[:5])
print(arr[-5:])

That often gives a more useful signal than dumping millions of values to the console.

Resetting Print Options

If you changed global settings with np.set_printoptions, you can reset them later:

python
np.set_printoptions(edgeitems=3, infstr='inf', linewidth=75,
                    nanstr='nan', precision=8, suppress=False,
                    threshold=1000)

In practice, though, using np.printoptions for local scope is often easier than manually restoring global defaults.

Common Pitfalls

One common mistake is thinking the array itself is truncated. NumPy usually truncates only the string representation, not the underlying data.

Another mistake is setting global print options in a notebook and then forgetting about them. Later cells may produce huge unreadable outputs because the threshold stays at infinity.

Developers also sometimes change linewidth and expect hidden elements to reappear. Line width affects wrapping, not truncation by element count.

Finally, printing a huge full array can be technically correct and still be the wrong debugging tool. For very large arrays, slices and summaries are often more effective.

Summary

  • Use np.set_printoptions(threshold=np.inf) to disable truncation globally.
  • Use np.printoptions(threshold=np.inf) when you want the change only temporarily.
  • Adjust linewidth if the output wraps too aggressively.
  • 'np.array2string is useful when you need the full array as text.'
  • Full output is sometimes less useful than slices or summary statistics for very large arrays.

Related reading
Course
Intermediate
27 lessons
15 hours
DSA Fundamentals

Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.