Print all elements of a large matrix using Python

Viewed 94

I have a 100x100 matrix but when I try to print it, it shows only few elements and not all of them. How do I generate all the elements in the output window or perhaps save in a .txt file?

import numpy as np
T=np.random.rand(100,100)
print(T)

Output:

[[0.2594114  0.82053856 0.34180207 ... 0.22343847 0.60514364 0.03521541]
 [0.92437952 0.03159018 0.97917483 ... 0.43370336 0.18015657 0.05756589]
 [0.876843   0.32627662 0.13961996 ... 0.07525198 0.03746563 0.80880022]
 ...
 [0.33922583 0.85408368 0.78105249 ... 0.59302032 0.99109042 0.28213881]
 [0.68913619 0.38941733 0.02607893 ... 0.33107884 0.26118189 0.09754887]
 [0.99950824 0.51556755 0.7743047  ... 0.03109424 0.91644689 0.35999142]]
1 Answers

To display the full output, use np.set_printoptions:

import numpy as np
import sys

np.set_printoptions(threshold=sys.maxsize)
T = np.random.rand(100, 100)
print(T)

To save the matrix in a file, use np.savetxt:

np.savetxt('out.txt', T)
Related