How to print the full NumPy array without truncating?

In this tutorial, we will learn how to print the full NumPy array without truncating? By Pranit Sharma Last updated : May 23, 2023

When the compiler deals with a big NumPy array in the shell, the Python interpreter shows only a small/truncated part of the array, representing that some values are missing in the original representation of the array with the triple dots. We need to find a way so we can print the full array as the output.

Printing the full NumPy array without truncation

To print the full NumPy array without truncating, use numpy.set_printoptions() by passing an argument threshold=np.inf or threshold=sys.maxsize.

Let us understand with the help of an example,

Python program to print the full NumPy array without truncating

# Import numpy
import numpy as np

import sys

# Creating a numpy array
arr = np.arange(10000)

# Display Original Array
print("Original Array:\n",arr,"\n")

# Creating a numpy array
arr = np.arange(100)
# Using printoptions method
np.set_printoptions(threshold=sys.maxsize)

# Display Original Array again
print("New Array:\n",arr,"\n")

Output

The output of the above program is:

Original Array:
 [   0    1    2 ... 9997 9998 9999] 

New Array:
 [ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
 96 97 98 99]
 

Output (Screenshot)

Example: How to print the full NumPy array without truncating?frame

Python NumPy Programs »


Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.