如果我创建了多个矩阵,如何将它们组合成一个数组?我有8个矩阵,每个矩阵有200行和200列,我需要将它们组合成dim = 200,200,8的数组。因此,我希望每个矩阵都可以作为数组的一部分。
最佳答案
这是两个例子。您可以轻松地将其扩展到八个
# create two matricies with however many rows and columns
x <- matrix( 1:9 , 3 , 3 )
y <- matrix( 10:18 , 3 , 3 )
# look at your starting data
x
y
# store both inside an array, with the same first two dimensions,
# but now with a third dimension equal to the number of matricies
# that you are combining
z <- array( c( x , y ) , dim = c( 3 , 3 , 2 ) )
# result
z
关于arrays - 将矩阵合并到R中的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15213463/