将2D numpy数组重塑为4D数组

时间:2019-11-09 19:02:40

标签: python-3.x numpy conv-neural-network

我有一个y_train(4D)矩阵,其内容为(33,224,224,1),其中(n_images,n_pixels_y,n_pixels_x,n_bands)需要使用Flatten转换为2D向量

现在我需要进行逆过程并将2D向量转回具有相同尺寸的4D矩阵,什么是最好的方法?

我一直在尝试使用整形,但是效果不是很好

例如:

y_pred = modelo.predict(x_test)
print(y_pred.shape) #this results in the current shape that is (33, 50176)


img = np.reshape(y_pred[1], (33,224,224,1))
plt.imshow(img, cmap='gray')
plt.show() #this results in a error 'cannot reshape array of size 50176 into shape (33,224,224,1)'

0 个答案:

没有答案