【问题标题】:regarding proper way of broadcasting input array from one shape into another shape关于将输入数组从一种形状广播到另一种形状的正确方法
【发布时间】:2017-04-02 21:05:29
【问题描述】:

有一个函数,我在调用这个函数时收到以下消息

功能是调整给定图像集的大小,并将转换后的图像放入新集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

【问题讨论】:

    标签: python numpy scipy scikit-learn scikit-image


    【解决方案1】:

    我假设您想将“1”维度滚动到正确的位置:

    z = np.moveaxis(z, 1, -1).shape
    

    之后,您可以使用 skimage 或 scipy.ndimage 对每个图像运行 for 循环并重塑形状。

    小心下采样!您可能需要先应用高斯模糊,以确保考虑到所有数据。

    【讨论】:

      猜你喜欢
      • 2021-10-08
      • 2010-12-31
      • 1970-01-01
      • 2020-10-06
      • 2020-11-23
      • 2021-08-13
      • 2021-01-20
      • 2018-05-19
      • 2021-07-06
      相关资源
      最近更新 更多