pythonフォルダの下のすべてのファイルを読み込む方法
4533 ワード
#
from numpy import *
from os import listdir #
def coatl(filename):#converting array to list
ve1=zeros((1,1024))
file1=open(filename)
for i in range(32):
line=file1.readline()
for k in range(32):
ve1[0,i*32+k]=int(line[k])
return ve1
#
filebox=listdir("D:\pfl\\trainingDigits") #
print(filebox[1:8])
#['0_1.txt', '0_10.txt', '0_100.txt', '0_101.txt', '0_102.txt', '0_103.txt', '0_104.txt']
len1=len(filebox)
vel1=zeros((len1,1024))
for i in range(len1):
finr=filebox[i]
vel1[i]=coatl("D:\pfl\\trainingDigits\%s"%finr)#
print(vel1)
#[[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
...,
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]]