I have a number of numpy arrays which I generate iteratively. I want to save each array to a file. I then generate the next array and append it to the file and so forth (if I did it in one go I would use too much memory). How do I best do that? Is there a way of making us of numpy functions such as e.g. numpy.savetxt? (I couldn't find an append option for that function.)
My current code is:
with open('paths.dat','w') as output:
for i in range(len(hist[0])):
amount = hist[0][i].astype(int)
array = hist[1][i] * np.ones(amount)
for value in array:
output.write(str(value)+'\n')
genfromtxtto reproduce the list (alas, it needs to be written to the drive first). I could combine the arrays generated bygenfromtxtbut they will be very large so the less I do with them the better.