-1
Hello! I have a code in Python3 and in each looping it generates 5 column arrays. For the first looping I was able to record each array as a column in a txt using numpy.savetxt:
array_aux1[int(j/tau), 0] = scale
array_aux2[int(j/tau), 0] = j
array_aux3[int(j/tau), 0] = spectrum_gapped[i]
array_aux4[int(j/tau), 0] = np.real(coef_gapped)
array_aux5[int(j/tau), 0] = np.imag(coef_gapped)
if i == 1:
np.savetxt("teste.txt",
np.hstack([array_aux1, array_aux2, array_aux3, array_aux4, array_aux5]),
fmt = ["%.5e", "%.5e", "%.5e", "%.5e", "%.5e"],
delimiter = '\t'
)
The problem is that I want to open this file again for all the looping "i’s" and first add a blank line and then save the new generated arrays. I tried to continue the condition by opening the "test.txt" file with the "append" parameter and using np.savetxt again:
else:
file = open("teste.txt", "a")
file.write('\n')
np.savetxt("teste.txt",
np.hstack([array_aux1, array_aux2, array_aux3, array_aux4, array_aux5]),
fmt = ["%.5e", "%.5e", "%.5e", "%.5e", "%.5e"],
delimiter = '\t'
)
What happens is that the previous matrices are not preserved. It is not the case that the blank line is inserted or the previous results are preserved. What should be done in this case? Does anyone have any suggestions? Thank you.
To people putting "downvote" in this question, I would like to know the reason why.
– jsbueno
I also don’t understand why my question is getting these "downvotes". But this is unusual around here. Soon someone answers and helps!@
– Luciano Magrini
to the account, it has not been unusual - some users apparently have the mindset of "our I don’t know how to answer this - so I’m going to downvote". The idea of my question above is that people realize what they are doing.
– jsbueno