I have a simple question with Python numpy. I have a numpy array as follows.
a = [ [1000 2 3] [4 5000 6] [7 8 9000] ]
I want to be able to print 3 slices of the array to a txt file so that the elements in the column line up.
For example, I would like to write a loop
for i in range(0,3): print a[i,:]
and have the txt file have all the elements lined up.
1000 2 3
4 5000 6
7 8 9000
I looked at numpy.savetxt but didn't see any print formatting(like printf) option. I also redirected my output stream to a file with
sys.stdout = open("file.txt", "w")
and used print statements but didn't know how to format a data slice(a[i,:]).
sys.stdout = open("file.txt", "w") for i in range(0,3): print x[i,:]?? how to do print format here
Can anyone help me? Thanks.