How to Display Full NumPy Array Without Truncation
When printing NumPy arrays, you often encounter truncated representations. To display the entire array, utilize the numpy.set_printoptions function.
import sys import numpy # Set threshold to maximum size to disable truncation numpy.set_printoptions(threshold=sys.maxsize)
Consider the following example:
>>> numpy.arange(10000) array([ 0, 1, 2, ..., 9997, 9998, 9999]) >>> numpy.arange(10000).reshape(250, 40) array([[ 0, 1, 2, ..., 37, 38, 39], [ 40, 41, 42, ..., 77, 78, 79], [ 80, 81, 82, ..., 117, 118, 119], ..., [9880, 9881, 9882, ..., 9917, 9918, 9919], [9920, 9921, 9922, ..., 9957, 9958, 9959], [9960, 9961, 9962, ..., 9997, 9998, 9999]])) >>> numpy.arange(10000).reshape(250, 40) array([
,
,[0 1 2 ... 9997 9998 9999] [[ 0 1 2 ... 37 38 39] [ 40 41 42 ... 77 78 79] [ 80 81 82 ... 117 118 119] ... [9880 9881 9882 ... 9917 9918 9919] [9920 9921 9922 ... 9957 9958 9959] [9960 9961 9962 ... 9997 9998 9999]]
Now, using numpy.set_printoptions, we can print the full array without truncation:
[0 1 2 ... 9997 9998 9999] [[ 0 1 2 ... 37 38 39] [ 40 41 42 ... 77 78 79] [ 80 81 82 ... 117 118 119] ... [9880 9881 9882 ... 9917 9918 9919] [9920 9921 9922 ... 9957 9958 9959] [9960 9961 9962 ... 9997 9998 9999]]
Output:
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3