无法将大小为 (x,) 的数组重塑为形状 (x,y,z,1)
cannot reshape array of size (x,) into shape (x,y,z,1)
我正在尝试将形状为 (2200,)
的 numpy ndarray 转换为形状为 (2200,250,250,1)
的 numpy ndarray。每行包含一个图像 (shape: 250,250,1)
这是我的对象:
type(x_train_left)
打印 numpy.ndarray
x_train_left.shape
打印 (2200,)
type(x_train_left[0])
打印 numpy.ndarray
x_train_left[0].shape
打印 (250, 250, 1)
但出于某种原因,当我尝试将 x_train_left
重塑为 (2200,250,250,1)
时,出现以下错误:
ValueError: cannot reshape array of size 2200 into shape (2200,250,250,1)
感谢您的帮助,我搜索了重复的主题,但它们都有不同的问题。
我找到了非常简单的解决方案:
np.stack(x_train_left)
然后当我尝试时:
x_train_left.shape
打印 (2200, 250, 250, 1)
我正在尝试将形状为 (2200,)
的 numpy ndarray 转换为形状为 (2200,250,250,1)
的 numpy ndarray。每行包含一个图像 (shape: 250,250,1)
这是我的对象:
type(x_train_left)
打印 numpy.ndarray
x_train_left.shape
打印 (2200,)
type(x_train_left[0])
打印 numpy.ndarray
x_train_left[0].shape
打印 (250, 250, 1)
但出于某种原因,当我尝试将 x_train_left
重塑为 (2200,250,250,1)
时,出现以下错误:
ValueError: cannot reshape array of size 2200 into shape (2200,250,250,1)
感谢您的帮助,我搜索了重复的主题,但它们都有不同的问题。
我找到了非常简单的解决方案:
np.stack(x_train_left)
然后当我尝试时:
x_train_left.shape
打印 (2200, 250, 250, 1)