Open In App

Print full Numpy array without truncation

Last Updated : 29 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The goal here is to print the full NumPy array without truncation, meaning all elements should be displayed regardless of the array’s size. By default, NumPy truncates large arrays to avoid overwhelming the display. However, there are different methods to configure the printing options so that the entire array is shown. Let’s explore a few approaches to accomplish this.

Using np.set_printoptions

np.set_printoptions function control how NumPy arrays are printed. By setting the threshold parameter to sys.maxsize, you are telling NumPy to print the entire array without truncating it, regardless of its size.

[GFGTABS]
Python

import numpy as np
import sys

a = np.arange(101)
np.set_printoptions(threshold=sys.maxsize)
print(a)


[/GFGTABS]

Output

Output55yy

Using np.set_printoptions

Explanation: np.set_printoptions(threshold=sys.maxsize) ensures the entire array is printed without truncation, regardless of size.

Using np.array2string with separator and max_line_width

np.array2string converts a NumPy array into a string representation, with customizable formatting options. The separator option defines how elements in the array are separated and max_line_width determines how wide each line of the output can be before it breaks into a new line.

[GFGTABS]
Python

import numpy as np
import sys 

a = np.arange(101)
print(np.array2string(a, separator=',', max_line_width=sys.maxsize))


[/GFGTABS]

Output

Output

Using np.array2string

Explanation: This code converts the array a into a string with elements separated by commas and ensures the entire array is printed on a single line without line breaks.

Using list()

This method converts a NumPy array into a Python list, which can be printed more easily or processed using standard Python list operations. NumPy arrays are more efficient for numerical operations, but sometimes you might need the flexibility of lists.

[GFGTABS]
Python

import numpy as np

a = np.arange(101)
print(list(a))


[/GFGTABS]

Output

[np.int64(0), np.int64(1), np.int64(2), np.int64(3), np.int64(4), np.int64(5), np.int64(6), np.int64(7), np.int64(8), np.int64(9), np.int64(10), np.int64(11), np.int64(12), np.int64(13), np.int64(14),...

Explanation: list(a) converts the NumPy array a into a Python list and prints it.

Using np.printoptions

np.printoptions context manager allows you to temporarily modify printing options within a specific code block. By using np.printoptions with threshold=sys.maxsize, you can print large arrays fully without truncation during the block execution.

[GFGTABS]
Python

import numpy as np
import sys 

a = np.arange(101)
with np.printoptions(threshold=sys.maxsize):
    print(a)


[/GFGTABS]

Output

Output

Using printoptions

Explanation: This code temporarily changes the print settings to display the entire array without truncation. The print(a) then prints the full array, showing all elements.



Next Article
Practice Tags :

Similar Reads