Say that I got this ndarray using numpy that I want to write to a text file. :
[[1 2 3 4]
[5 6 7 8]
[9 10 11 12]]
This is my code:
width, height = matrix.shape
with open('file.txt', 'w') as foo:
for x in range(0, width):
for y in range(0, height):
foo.write(str(matrix[x, y]))
foo.close()
The problem is that I get all the lines of the ndarray in just one line, however I want it to be written to the file as this :
1 2 3 4
5 6 7 8
9 10 11 12