readWriteTools.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:ExoSOFT 作者: kylemede 项目源码 文件源码
def periodicDataDump(filename,d):
    """
    dump a ndarray to disk.  If first time, just dump it.
    Else, load current ary and cat d to it before dumping.
    """
    old=True
    if len(d)!=0:
        if os.path.exists(filename):
            if old:
                d0 = np.load(filename)
                np.save(filename,np.concatenate((d0,d)))
            else:
                with open(filename,'a') as outfile:
                    for i in range(0,d.shape[0]):
                        outstr = ''
                        for val in d[i]:
                            outstr+='%.14g  ' % (val)
                        outstr += '\n'
                        outfile.write(outstr)#nparyTolistStr(d[i],brackets=False,dmtr=' ')+'\n')
                        #outfile.write(re.sub("\n ","\n",re.sub("[\\[\\]]","",np.array2string(d,precision=16))))
        else:
            if old:
                np.save(filename,d)
            else:
                with open(filename,'w') as outfile:
                    for i in range(0,d.shape[0]):
                        outstr = ''
                        for val in d[i]:
                            outstr+='%.14g  ' % (val)
                        outstr += '\n'
                        outfile.write(outstr)#nparyTolistStr(d[i],brackets=False,dmtr=' '))
                        #outfile.write(re.sub("\n ","\n",re.sub("[\\[\\]]","",np.array2string(d))))
                        #print nparyTolistStr(d[i],brackets=False,dmtr=' ')
                    #raise IOError('\n\n'+s)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号