Python实现将多个npy文件转换成对应个数的txt文件
程序员文章站
2022-03-22 08:10:22
...
import os
import numpy as np
path='/CNN/path' #一个文件夹下多个npy文件,
txtpath=‘/CNN/txtpath'
namelist=[x for x in os.listdir(path)]
namelist.sort(key=lambda x:int(x[:-4])) #npy file name in order
#print len(namelist)#1674
for i in range( len(namelist) ):
datapath=os.path.join(path,namelist[i]) #specific address
data = np.load(datapath).reshape([-1, 2]) # (39, 2)
np.savetxt('%s/%d.txt'%(txtpath,i),data)
print 'over'
上一篇: 【攻防世界】open-source