I want to do in a for loop something like this:
for i in range(n):
x = vector()
np.savetxt('t.txt', x, newline=" ")
but I want to save each array x as a new line in my file, but this doesn't happen with the code above, can anybody help? Thanks!
I would go for something like (untested!):
There are some decisions to make:
This of course is based on the assumption, that you can't wait to grab all data before writing all at once! (online-setting)
Try this:
That is, pass an already open file handle to the
numpy
'ssavetxt
function. This way it will not overwrite existing content. Also see Append element to binary file