Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How to print the full NumPy array, without truncation?

At the point when I print a NumPy array, I get a truncated representation, yet I need the full array.

Is there any approach to do this?
Examples:
>>> 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]])
by

3 Answers

aashaykumar
Use numpy.set_printoptions:

import sys
import numpy
numpy.set_printoptions(threshold=sys.maxsize)
kshitijrana14
import numpy as np
np.set_printoptions(threshold=np.inf)

I suggest using np.inf instead of np.nan which is suggested by others. They both work for your purpose, but by setting the threshold to "infinity" it is obvious to everybody reading your code what you mean. Having a threshold of "not a number" seems a little vague to me.
sandhya6gczb
One of the way to get the solution to the above question is

numpy.arange(100).reshape(25,4).tolist()

Login / Signup to Answer the Question.