简体   繁体   English

无法从 1D 原始补丁到 2D 图像补丁 reshape.npy 数组

[英]Can't reshape .npy array from 1D raw patches to 2D image patches

Need to reshape 1-d 2914 pxls per picture array to 2-d 62*47 array, from a dataset需要从数据集中将每个图片数组的一维 2914 像素重塑为二维 62*47 数组

tried to creative a patches variable with np.load attached and then using np.shape(62,47) on said variable, got a "tuple isnt callable error"试图创建一个附加了 np.load 的补丁变量,然后在所述变量上使用 np.shape(62,47),得到一个“tuple isnt callable error”

np.shape is not a function. It returns the shape of your array, which is a tuple. np.shape不是 function。它返回数组的形状,它是一个元组。 You need to use the np.reshape function.您需要使用np.reshape function。

import numpy as np

pic = np.random.rand(2914)
print(f"Shape: {pic.shape}")

pic = np.reshape(pic, (62, 47))
print(f"Shape: {pic.shape}")

print(f"np.shape: {np.shape(pic)}")
print(f"type of np.shape: {type(np.shape(pic))}")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM