NumPy
Python
Programming
Array Printing
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 shortens large arrays when it prints them so terminal output stays readable. That is helpful most of the time, but when you are debugging or inspecting generated data, you may want the full array representation with no ellipsis in the middle.

Use set_printoptions to Disable Summarization

NumPy controls array display through print options. The key setting is threshold, which decides when summarization starts.

If you want the full array, set the threshold to a very large value:

python
1import sys
2import numpy as np
3
4arr = np.arange(30).reshape(5, 6)
5
6np.set_printoptions(threshold=sys.maxsize)
7print(arr)

Output:

text
1[[ 0  1  2  3  4  5]
2 [ 6  7  8  9 10 11]
3 [12 13 14 15 16 17]
4 [18 19 20 21 22 23]
5 [24 25 26 27 28 29]]

Using sys.maxsize tells NumPy to keep the full representation rather than switching to a summarized form.

Prefer a Context Manager for Temporary Changes

np.set_printoptions changes global printing behavior for the current process. That is fine in a short script, but it can surprise you in tests or notebooks if you forget to undo it.

A safer option is np.printoptions, which applies only inside a with block:

python
1import sys
2import numpy as np
3
4arr = np.arange(100)
5
6with np.printoptions(threshold=sys.maxsize):
7    print(arr)
8
9print("Outside the context manager, defaults are restored.")

This keeps the change local and makes debugging code easier to clean up.

Use array2string When You Need a String

Sometimes you do not want to print immediately. You may want to write the array to a log, a file, or a test failure message. In that case, np.array2string is useful.

python
1import sys
2import numpy as np
3
4arr = np.arange(12).reshape(3, 4)
5text = np.array2string(arr, threshold=sys.maxsize)
6
7print(text)

That gives you the same idea as print(arr), but as a string you can store or combine with other output.

Formatting Still Matters

Disabling truncation only changes whether the array is summarized. Other print options still affect formatting. For example:

  • 'linewidth controls line wrapping'
  • 'precision affects floating-point display'
  • 'suppress changes scientific notation behavior'

Example:

python
1import sys
2import numpy as np
3
4arr = np.array([1.23456789, 1000000.0, 0.0000123])
5
6with np.printoptions(
7    threshold=sys.maxsize,
8    precision=3,
9    suppress=True,
10    linewidth=120,
11):
12    print(arr)

That can make full-array output much easier to read, especially for floating-point data.

Full Output Can Be Expensive

Printing the full contents of a very large array can flood your terminal, slow down a notebook cell, or create enormous logs. In many debugging sessions, printing a slice is better:

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

Or inspect statistics instead:

python
print(arr.shape)
print(arr.min(), arr.max(), arr.mean())

The point is not that full printing is bad. It is just a tool you should use deliberately.

Common Pitfalls

The biggest mistake is forgetting that set_printoptions changes global state. If later output looks strange, an earlier debugging line may have altered the defaults.

Another issue is confusing truncated display with truncated data. NumPy is only shortening the representation it prints. The array itself still contains all elements.

Developers also sometimes print massive arrays into logs and make the logs unusable. In production code, summaries are often more helpful than full raw dumps.

Finally, remember that notebook environments and pandas have their own display settings too. Changing NumPy options affects NumPy array formatting, but it does not automatically change every other library’s rendering rules.

Summary

  • Use np.set_printoptions(threshold=sys.maxsize) to print full arrays without summarization.
  • Prefer np.printoptions(...) when you want the change to be temporary.
  • Use np.array2string when you need the representation as a string.
  • Combine threshold changes with formatting options such as precision and linewidth when needed.
  • Full array printing is useful for debugging, but it can create overwhelming output on large datasets.

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.