Print full Numpy array without truncation
Last Updated :
29 Apr, 2025
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.
Python
import numpy as np
import sys
a = np.arange(101)
np.set_printoptions(threshold=sys.maxsize)
print(a)
Output
Using np.set_printoptionsExplanation: 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.
Python
import numpy as np
import sys
a = np.arange(101)
print(np.array2string(a, separator=',', max_line_width=sys.maxsize))
Output
Using np.array2stringExplanation: 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.
Python
import numpy as np
a = np.arange(101)
print(list(a))
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.
Python
import numpy as np
import sys
a = np.arange(101)
with np.printoptions(threshold=sys.maxsize):
print(a)
Output
Using printoptionsExplanation: 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.
Similar Reads
Print a NumPy Array Without Scientific Notation in Python We have given you a Numpy array. We are going to display the Numpy array without scientific notation and with the given precision. In this article, we are going to explore different methods in Python. Example Input 1: Array = [123.456, 0.123456, 987.123] , Precision = 2Output 1: [123.46 0.12 987.12]
3 min read
numpy.array_str() in Python numpy.array_str()function is used to represent the data of an array as a string. The data in the array is returned as a single string. This function is similar to array_repr, the difference being that array_repr also returns information on the kind of array and its data type. Syntax : numpy.array_st
2 min read
Create a Numpy array filled with all zeros - Python In this article, we will learn how to create a Numpy array filled with all zeros, given the shape and type of array. We can use Numpy.zeros() method to do this task. Let's understand with the help of an example:Pythonimport numpy as np # Create a 1D array of zeros with 5 elements array_1d = np.zeros
2 min read
NumPy - Create array filled with all ones To create an array filled with all ones, given the shape and type of array, we can use numpy.ones() method of NumPy library in Python.Pythonimport numpy as np array = np.ones(5) print(array) Output:[1. 1. 1. 1. 1.] 2D Array of OnesWe can also create a 2D array (matrix) filled with ones by passing a
2 min read
Convert Python List to numpy Arrays NumPy arrays are more efficient than Python lists, especially for numerical operations on large datasets. NumPy provides two methods for converting a list into an array using numpy.array() and numpy.asarray(). In this article, we'll explore these two methods with examples for converting a list into
4 min read