When working with NumPy arrays, it's common to encounter a problem where large arrays are truncated when printed. This can make it difficult to inspect the full contents of the array. Fortunately, there is a simple solution that allows you to print the full array without any truncation.
To print the full NumPy array, you can use the numpy.set_printoptions function. This function takes several arguments, including the threshold argument, which specifies the maximum number of elements to be printed before truncation occurs. By setting the threshold argument to sys.maxsize, the function will print the entire array without any truncation.
Here's an example:
import sys import numpy my_array = numpy.arange(10000) numpy.set_printoptions(threshold=sys.maxsize) print(my_array)
This will print the full array without any truncation:
[ 0 1 2 ... 9997 9998 9999]
The above solution can also be applied to multidimensional arrays. For instance, to print a 250x40 array without truncation:
my_array = numpy.arange(10000).reshape(250, 40) numpy.set_printoptions(threshold=sys.maxsize) print(my_array)
This will print the full array without any truncation.
The above is the detailed content of How Can I Print a Full NumPy Array Without Truncation?. For more information, please follow other related articles on the PHP Chinese website!