1234567891011121314151617181920212223242526 |
- import numpy
- import os
- import re
- def parseCoefficients(fdir,outName):
- outlines=[]
- for s in numpy.arange(0.05,3,0.01):
- out='{:.2f}'.format(s)
- for c in ['alpha','beta']:
- fname='{}_coefficients_n=20_sigma={:.2f}.txt'.format(c,s)
- fpath=os.path.join(fdir,fname)
- #print('{}: {}'.format(fname,os.path.isfile(fpath)))
- with open(fpath,'r') as f:
- lines=f.read().splitlines()
- lines=[re.sub(r' *','',q) for q in lines]
- lines=[re.sub(r'E','e',q) for q in lines]
- qv=[float(q) for q in lines]
- #use Decimal, if you want to preserve all decimals
- #print('nread: {} {:.20f} {}'.format(len(qv),qv[0],lines[0]))
- out+=' '
- out+=' '.join(lines)
- #print(' '.join(lines))
- outlines.append(out)
- print('nlines {}'.format(len(outlines)))
- with open(os.path.join(fdir,outName),'w') as f:
- f.write('\n'.join(outlines))
|