代码之家  ›  专栏  ›  技术社区  ›  stschn

将3D阵列的图像列表转换为一个4D阵列

r
  •  0
  • stschn  · 技术社区  · 6 年前

    我有一个三维阵列的图像列表,尺寸为宽x高x通道。现在我想把R中的这个列表转换成一个4D数组,数组的尺寸是长×宽×高×通道。

    以下R代码工作正常,但我认为有一个更有效的解决方案:

    # Settings
    img_width <- 200
    img_height <- 100
    img_channels <- 3
    
    # Preallocate multidimensional array
    marray <- array(NA, dim = c(length(imagelist), img_width, img_height, img_channels))
    
    # Transfer data to array
    for (i in 1:length(imagelist)) {
      img <- imagelist[[i]]
      marray[i,,,] <- img
    }
    

    提前谢谢!

    0 回复  |  直到 6 年前