[ How to save an array into a text file with a format f10.0? ]
from numpy import *
savetxt(txtfilename,ndarr,fmt='?')
If I have a number 6.5, I want to save it in a format such that it will become 00000006.5 . I am not sure whether this kind of format is called f10.0 but I supposed that here first. Please correct me if I am wrong.
I have tried to use a format which is '%10.0f' but it doesn't work.
So what kind of format should I enter so that the format f10.0 can be achieved?
Thank you for your help.
UTC+8:00 2014-03-24 11:55AM
Thanks for the answering from joel, it works.
And I would like to share a indirect method that I used.
data_fmt=array([['{0:010}'.format(i) for i in j] for j in data_csv])
savetxt(os.path.join(metpath,'data_fmt.txt'),data_fmt,fmt='%s',delimiter='')
Have a nice day!
Answer 1
Try "%010.1f". This will work in your specific example:
>>> '%010.1f' % 6.5
'00000006.5'
A leading flag of 0 is needed to format a float so it's padded with leading zeroes.