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

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

问题描述

如果我有,我已经创建了几个矩阵,我怎么能结合他们到一个数组?我有8个矩阵,每个都有200行和200列,我需要将它们合并成暗淡= 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天全站免登陆