MCPcopy Create free account
hub / github.com/Dod-o/Statistical-Learning-Method_Code / convert

Function convert

transMnist/transMnist.py:11–30  ·  view source on GitHub ↗
(imgf, labelf, outf, n)

Source from the content-addressed store, hash-verified

9转换后的CVS文件在Mnist文件夹中
10'''
11def convert(imgf, labelf, outf, n):
12 f = open(imgf, "rb")
13 o = open(outf, "w")
14 l = open(labelf, "rb")
15
16 f.read(16)
17 l.read(8)
18 images = []
19
20 for i in range(n):
21 image = [ord(l.read(1))]
22 for j in range(28*28):
23 image.append(ord(f.read(1)))
24 images.append(image)
25
26 for image in images:
27 o.write(",".join(str(pix) for pix in image)+"\n")
28 f.close()
29 o.close()
30 l.close()
31
32if __name__ == '__main__':
33 convert(".\Mnist\\t10k-images.idx3-ubyte", ".\Mnist\\t10k-labels.idx1-ubyte",

Callers 1

transMnist.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected