I am trying to save a 100x100x100 array of integers to a file with the date and time it was saved as a header. It doesn't need to be human-readable (except for the time-stamp header) so I was planning to use numpy.save(), take one slice at a time and save it to the file, but this does not append to the end of the file, it overwrites each time so the file only ends up containing the last slice.
Is there something like save() or savetxt() which appends to a file rather that overwrites?
Note: if it makes it easier, could I put the date/time into the filename when it saves instead of into the header?
My current attempt looks something like this:
with open("outfile.txt",'w') as mfile:
mfile.write(strftime("%x %X\n"))
for i in range(len(x)):
np.savetxt("outfile.txt",x[i])
numpy.savetakes a file as first argument, did you open with an'a'flag ?reshapeorflattenon your array in order to obtain low-dimensional versions. You need to remember your array shape while loading however (but that is probably the case anyway).