It does not matter whether you are debugging your code, inspecting your extensive data, or running a small-scale simulation; you have to print an array without truncation in a shell or Python interpreter to verify the correctness of computations by examining all elements of an array.
With truncation, your numpy array looks like this:
Without truncation, your numpy array looks like this:
Now that you understand the difference, let’s check out how to do it.
You can print a numpy array without truncation numpy.set_printoptions() function and pass either sys.maxsize or np.inf as an argument to that function.
Method 1: Using numpy.set_printoptions() with sys.maxsize
The numpy.set_printoptions() function sets “printing options” for the array. These options decide how numpy objects are displayed on the console or screen.
We won’t go into every argument of the set_printoptions() method, but one argument, called “threshold,” is fundamental.
By default, NumPy truncates large arrays to avoid overwhelming the output.
We will use the full repr without summarization, so we will pass sys.maxsize as an argument to display each element of the array in the console.
Essentially, we set the threshold to the maximum representable integer, thereby disabling truncation.
import numpy as np import sys # Printing all values of array without truncation np.set_printoptions(threshold=sys.maxsize) # Creating a 1D array with 121 values arr = np.arange(121) print(arr)
Output
You can see that each element of the array has been delayed.
Method 2: Using numpy.set_printoptions() with numpy.inf
The numpy.inf means infinity. We are setting infinity as a threshold, which means the same thing.
import numpy as np # Printing all values of array without truncation # By setting threshold to np.inf np.set_printoptions(threshold=np.inf) # Creating a 1D array with 121 values arr = np.arange(90) print(arr)
Output
Why shouldn’t we print large arrays to the console?
Printing extremely large arrays to the console can be very difficult to read, and it may cause performance issues by consuming excessive memory and potentially causing your system to hang.
A more effective way to print out a large array is to summarize the data meaningfully or utilize more specialized tools. Only if there is an absolute requirement for this type of operation should you do it.




