我給出了一個向量,並希望將其轉換爲某個塊矩陣。考慮一個簡單的例子:矢量分塊矩陣
k <- c(1,2,3)
a <- rep(apply(expand.grid(k, k), 1, prod), each=3)
a
[1] 1 1 1 2 2 2 3 3 3 2 2 2 4 4 4 6 6 6 3 3 3 6 6 6 9 9 9
這個載體應形式的分塊矩陣排列:
rbind(
cbind(diag(a[1:3]), diag(a[4:6]), diag(a[7:9])),
cbind(diag(a[10:12]), diag(a[13:15]), diag(a[16:18])),
cbind(diag(a[19:21]), diag(a[22:24]), diag(a[25:27]))
)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,] 1 0 0 2 0 0 3 0 0
[2,] 0 1 0 0 2 0 0 3 0
[3,] 0 0 1 0 0 2 0 0 3
[4,] 2 0 0 4 0 0 6 0 0
[5,] 0 2 0 0 4 0 0 6 0
[6,] 0 0 2 0 0 4 0 0 6
[7,] 3 0 0 6 0 0 9 0 0
[8,] 0 3 0 0 6 0 0 9 0
[9,] 0 0 3 0 0 6 0 0 9
現在,這當然是一個小而簡單的例子,我想做到這一點的更大的矢量/矩陣。因此,我的問題:是否有一種通用的方法來對齊某個形式的塊矩陣中的矢量(沒有循環)?
也許相關的帖子:https://stackoverflow.com/questions/17495841/block-diagonal-binding-of-matrices – zx8754