I have the following numpy array:
matrix = numpy.zeros([30, 30], dtype = numpy.int32)
I later change the values of this array and save it to a file like so:
conf_mat = open("conf_mat.txt", "w")
conf_mat.write(str(matrix))
But the result in the file looks like this
[[ 0 0 0 8 161 0 18 0 0 0 0 0
13 0 1 0 140 2 0 0 8 0 14 0
0 0 0 0 0 0]
[ 0 0 0 41 31 0 39 0 0 0 0 0
44 0 0 0 21 39 0 0 39 0 105 0
0 0 0 0 0 0]
[ 0 0 0 71 162 0 155 0 0 1 0 0
6 0 0 0 350 110 0 0 8 0 21 0
0 0 0 0 0 0]
...
As you can see 1 row of the matrix is separated into 3 lines in the document. How can I write the whole row of the matrix on just one row of the file?
PS: I don't know if it makes a difference, but I am using a remote linux server via ssh connection.
str(matrix)which can be a hassle to read the file back wih all the square brackets. It's best to stick to numpy.loadtxt as other answers have suggested.