This question is connected to others already existing (such as this), but I could not solve by following the solutions provided in there. So I try to ask again.
I have 7 parameters, say a1, a2, b1, b2, b3, b4 and b5.
The 'a' parameters are integers, while the 'b' parameters are floats.
As an example, take
a1=1, a2=500, b1=1.0, b2=1.0, b3=-0.866025, b4=0.0, b5=-0.1.
I would like to save these parameters into a file. The code for doing this reads:
f = open("params.txt",'w')
arr=np.array((a1,a2,b1,b2,b3,b4,b5))
arrform=' '.join(['%d']*2 + ['%f']*5)
np.savetxt(f,arr,fmt=arrform)
f.close()
When executing this code I get the following error message:
fmt has wrong number of % formats: %d %d %f %f %f %f %f
Could you, please, tell me what is my mistake?
print(arrform%(a1,a2,...), file=f)off.write(...)should be enough if those variables are scalars. You don't neednumpyto format and write a tuple of numbers.