关于将输入数组从一种形状广播到另一种形状的正确方法
regarding proper way of broadcasting input array from one shape into another shape
有一个函数,我在调用这个函数时得到了以下消息
功能是调整给定图像集的大小,并将变换后的图像放入新集中imgs_p
。
例如,输入 imgs
的形状为 (5635,1,420,580)
。我想改造一下(5635,64,80,1)
。这就是我所做的,但我收到的错误消息是 ValueError: could not broadcast input array from shape (80,64) into shape (80,1)
如何解决这个问题呢?谢谢。
def preprocess(imgs):
imgs_p = np.ndarray((imgs.shape[0],img_rows, img_cols,imgs.shape[1]), dtype=np.uint8)
print('imgs_p: ',imgs_p.shape)
for i in range(imgs.shape[0]):
print('imgs[i,0]: ',imgs[i,0].shape)
imgs_p[i,0]=resize(imgs[i,0],(img_rows,img_cols))
return imgs_p
我想你想将“1”维度滚动到正确的位置:
z = np.moveaxis(z, 1, -1).shape
此后您可以 运行 对每个图像进行 for 循环并使用 skimage 或 scipy.ndimage 重塑形状。
小心缩减采样!您可能想先应用高斯模糊以确保所有数据都被考虑在内。
有一个函数,我在调用这个函数时得到了以下消息
功能是调整给定图像集的大小,并将变换后的图像放入新集中imgs_p
。
例如,输入 imgs
的形状为 (5635,1,420,580)
。我想改造一下(5635,64,80,1)
。这就是我所做的,但我收到的错误消息是 ValueError: could not broadcast input array from shape (80,64) into shape (80,1)
如何解决这个问题呢?谢谢。
def preprocess(imgs):
imgs_p = np.ndarray((imgs.shape[0],img_rows, img_cols,imgs.shape[1]), dtype=np.uint8)
print('imgs_p: ',imgs_p.shape)
for i in range(imgs.shape[0]):
print('imgs[i,0]: ',imgs[i,0].shape)
imgs_p[i,0]=resize(imgs[i,0],(img_rows,img_cols))
return imgs_p
我想你想将“1”维度滚动到正确的位置:
z = np.moveaxis(z, 1, -1).shape
此后您可以 运行 对每个图像进行 for 循环并使用 skimage 或 scipy.ndimage 重塑形状。
小心缩减采样!您可能想先应用高斯模糊以确保所有数据都被考虑在内。