我想裁剪RGB图像,以便去除图像的上半部分。裁剪后,我想将图像连接到一个numpy数组(此处为图像)。但是我收到以下错误ValueError: all the input array dimensions except for the concatenation axis must match exactly
。我尝试了很多事情,但我的尝试似乎都没有运气。
我的代码看起来像
images = np.zeros((1, 32, 64, 3))
image = get_image() # has shape 1, 64, 64, 3
# removing the first coordinate didn't change the error.
images = np.concatenate([images, image[:, 32:63, :, :]], axis=0)
编辑:image[:, 32:63, :, :]
中的以下修改无法解决问题
a)[:,32:63,:,:]-> [32:63,:,:]
b)[:,32:63,:,:]-> [:] [32:63] [:] [:]
答案 0 :(得分:1)
您应该
images = np.zeros((1, 32, 64, 3))
image = get_image() # has shape 1, 64, 64, 3
# removing the first coordinate didn't change the error.
images = np.concatenate([images, image[:, 32:, :, :]], axis=0)
由于32:63省略了最后一个元素。 (也可以使用32:64)