MCPcopy Create free account
hub / github.com/Jack-Cherish/Machine-Learning / img2vector

Function img2vector

SVM/svm-svc.py:18–38  ·  view source on GitHub ↗

将32x32的二进制图像转换为1x1024向量。 Parameters: filename - 文件名 Returns: returnVect - 返回的二进制图像的1x1024向量

(filename)

Source from the content-addressed store, hash-verified

16"""
17
18def img2vector(filename):
19 """
20 将32x32的二进制图像转换为1x1024向量。
21 Parameters:
22 filename - 文件名
23 Returns:
24 returnVect - 返回的二进制图像的1x1024向量
25 """
26 #创建1x1024零向量
27 returnVect = np.zeros((1, 1024))
28 #打开文件
29 fr = open(filename)
30 #按行读取
31 for i in range(32):
32 #读一行数据
33 lineStr = fr.readline()
34 #每一行的前32个元素依次添加到returnVect中
35 for j in range(32):
36 returnVect[0, 32*i+j] = int(lineStr[j])
37 #返回转换后的1x1024向量
38 return returnVect
39
40def handwritingClassTest():
41 """

Callers 1

handwritingClassTestFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected