python-3.x - 将 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)'
解决方案
推荐阅读
- list - 将数字转换为 Prolog 中的列表?
- django - Django Concatenate charfields 并将其解析为 Datetime
- sql - 如何选择实体的计数,其中时间序列日期介于该实体的开始日期和结束日期之间
- file - 在单个 HTTP 响应中检索文件和一些数据
- python - 使用 sqlalchemy 连接到数据库产生 kwargs 错误
- html - 从不同的 HTML 文件中的手写 javascript 调用 GWT 方法
- javascript - 模态弹出窗口未关闭
- autoload - 打开我的网站时自动加载错误许可证授权
- amazon-web-services - Aws WorkMail 组织 ClientToken
- java - 什么时候绝对有必要对超类的参数化构造函数进行显式调用,为什么会这样?