欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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'
相关标签: code