初始化R中的矩阵列表 [英] Initialize a list of matrices in R

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

问题描述

我想知道是否存在一种快速的方法来初始化R中的矩阵列表.例如,我正在寻找一种(单线)以再现与以下相同的结果:

I was wondering if there's a quick way to initialize a list of matrices in R. For example I'm looking for a (one-liner) to reproduce the same results as the following:

output_array = list()
for(i in 1:10){
output_array[i] = diag(2)
}

谢谢!

推荐答案

也可以尝试* apply的包装:

Also try this wrapper of *apply:

replicate(10, diag(2), simplify=F)

这篇关于初始化R中的矩阵列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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