首页 > 解决方案 > 将 2D numpy 数组重塑为 4D 数组

问题描述

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

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

我一直在尝试使用 reshape,但它不是很有效

前任:

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)'

标签: python-3.xnumpyconv-neural-network

解决方案


推荐阅读