MCPcopy Index your code
hub / github.com/lawlite19/MachineLearning_Python / display_data

Function display_data

NeuralNetwok/NeuralNetwork.py:67–93  ·  view source on GitHub ↗
(imgData)

Source from the content-addressed store, hash-verified

65
66# 显示100个数字
67def display_data(imgData):
68 sum = 0
69 '''
70 显示100个数(若是一个一个绘制将会非常慢,可以将要画的数字整理好,放到一个矩阵中,显示这个矩阵即可)
71 - 初始化一个二维数组
72 - 将每行的数据调整成图像的矩阵,放进二维数组
73 - 显示即可
74 '''
75 m,n = imgData.shape
76 width = np.int32(np.round(np.sqrt(n)))
77 height = np.int32(n/width);
78 rows_count = np.int32(np.floor(np.sqrt(m)))
79 cols_count = np.int32(np.ceil(m/rows_count))
80 pad = 1
81 display_array = -np.ones((pad+rows_count*(height+pad),pad+cols_count*(width+pad)))
82 for i in range(rows_count):
83 for j in range(cols_count):
84 if sum >= m: #超过了行数,退出当前循环
85 break;
86 display_array[pad+i*(height+pad):pad+i*(height+pad)+height,pad+j*(width+pad):pad+j*(width+pad)+width] = imgData[sum,:].reshape(height,width,order="F") # order=F指定以列优先,在matlab中是这样的,python中需要指定,默认以行
87 sum += 1
88 if sum >= m: #超过了行数,退出当前循环
89 break;
90
91 plt.imshow(display_array,cmap='gray') #显示灰度图像
92 plt.axis('off')
93 plt.show()
94
95# 代价函数
96def nnCostFunction(nn_params,input_layer_size,hidden_layer_size,num_labels,X,y,Lambda):

Callers 1

neuralNetworkFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected