将矩阵组合成 R 中的数组 [英] Combining matrices into an array in R

查看:31
本文介绍了将矩阵组合成 R 中的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我创建了多个矩阵,如何将它们组合成一个数组?我有 8 个矩阵,每个矩阵有 200 行和 200 列,我需要将它们组合成一个数组,dim = 200,200,8.所以我希望我的每个矩阵都是我数组的一部分.

If I have several matrices that I have created, how can I combine them into one array? I have 8 matrices that each have 200 rows and 200 columns and I need to combine them into an array with dim = 200,200,8. So I want each of my matrices to be a slice of my array.

推荐答案

这是两个示例.您可以轻松地将其扩展到八个

here's the example for two. you can easily extend this to eight

# 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

这篇关于将矩阵组合成 R 中的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆