【问题标题】:Given a list of n 4x4 matrices, how do I combine them such that they follow consecutively resulting in a 4nx4 matrix给定一个 n 4x4 矩阵的列表,我如何组合它们以使它们连续跟随,从而产生一个 4nx4 矩阵
【发布时间】:2014-03-04 00:39:49
【问题描述】:

我想要做的是给定一个列表 [mat1, mat2, mat3, ..., matn],其中每个矩阵都是 4x4 创建一个大的 4nx4 矩阵:

mat1
mat2
mat3

我使用循环来执行此操作,但我的列表大约有 12000 个矩阵,并且需要很长时间……我怎样才能以更有效的方式执行此操作?

【问题讨论】:

  • 您好,请尝试通过将部分文本从标题移到问题正文中来澄清您的问题。

标签: r matrix merge


【解决方案1】:
do.call(rbind, list(mat1, mat2, mat3))

## Collect the matrices into a list
MATS <- lapply(paste0("mat", 1:n), function(x) get(x))

## rbind them all into one
do.call(rbind, MATS)

【讨论】:

  • 谢谢,这正是我所需要的!
【解决方案2】:

abind 包对这种事情很有用,因为它会直接接受一个列表。操作矩阵和数组绝对值得了解。

library(abind)
mat <- matrix(1, ncol = 4, nrow = 4)
abind(list(mat, mat), along = 1)

【讨论】:

    猜你喜欢
    • 2023-03-26
    • 2016-08-01
    • 1970-01-01
    • 2018-08-01
    • 2018-09-07
    • 1970-01-01
    • 2014-10-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多