If I understand correctly, it seems like you are trying to append to a file after each iteration (if your data file already exists), if so use:
f = open("data_file.txt", "a+")
The "a+" indicates you wish to append with any subsequent calls to write. Docs here. If you are doing a bunch of iterations, be sure to open the file outside of any loops.
Of course you could also loop to write each element of the new row after each iteration and then just write a newline with something like this:
#open file
for item in newRow:
#Your formatting will determine the specifics of this write
f.write(item)
f.write("\n")
Something like this does what I think you are getting at:
# Use with for file safety
with open('output.txt', 'w') as f:
for R in range(no_of_walkers):
x = 0.0
for t in range(t_max):
x = x + np.random.randint(-1, 2)
f.write(str(x) + ' ')
f.write('\n')
output.txt
1.0 1.0 1.0 1.0 1.0 0.0 0.0 -1.0 -2.0 -2.0
0.0 1.0 0.0 0.0 -1.0 0.0 1.0 0.0 1.0 1.0
-1.0 -1.0 -1.0 -2.0 -1.0 -1.0 -2.0 -1.0 -2.0 -3.0
-1.0 -1.0 0.0 1.0 0.0 1.0 2.0 1.0 2.0 1.0
1.0 0.0 -1.0 -2.0 -1.0 -1.0 0.0 1.0 1.0 0.0
As for efficiency, I'm pretty sure the way you were originally trying to write is better. See this post.