二维及其以下数组利用np.savetxt(filename,ndarray,fmt='',delimiter=' ',newline='/n')输出很方便,当数组超过2维,需要将数组进行切片,变成二维数组才可以输出,如:
import numpy as np
if not path is None:
with file(os.path.join(outpath,ctime+'_synopticscale_front_location.dat'), 'w') as outfile:
for slice_2d in path:
np.savetxt(outfile, slice_2d,fmt='%0.8f')
with file(os.path.join(outpath,ctime+'_synopticscale_front_type.dat'),'w')as outfile:
for slice_2d in smask:
np.savetxt(outfile,slice_2d,fmt='%8d')
np.savetxt(os.path.join(outpath,ctime+'_synopticscale_flont_influence_area.dat'), np.transpose(frontregion), fmt='%8d', delimiter=' ')
参考 https://stackoverflow.com/questions/3685265/how-to-write-a-multidimensional-array-to-a-text-file