gpt4 book ai didi

R matlab 包 : why is repmat inconsistent?

转载 作者:太空宇宙 更新时间:2023-11-03 20:02:26 26 4
gpt4 key购买 nike

我有一个关于 R 的 matlab 包的问题。这是我得到的结果

library(matlab)
a = matrix(1:4,2,2)
repmat(a,3,1)
[,1] [,2]
[1,] 1 2
[2,] 3 4
[3,] 1 2
[4,] 3 4
[5,] 1 2
[6,] 3 4

这是我所期望的。沿第一个维度复制三次。但是

b = matrix(1:6,2,3)
b
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6

repmat(b,3,1)
[,1] [,2]
[1,] 1 2
[2,] 3 4
[3,] 5 6
[4,] 1 2
[5,] 3 4
[6,] 5 6
[7,] 1 2
[8,] 3 4
[9,] 5 6

这是不一致的。我想要一个 6 x 3 矩阵作为

获得的矩阵
rbind(b,rbind(b,b))
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6
[3,] 1 3 5
[4,] 2 4 6
[5,] 1 3 5
[6,] 2 4 6

最佳答案

它看起来只是在进行堆叠之前转置矩阵。您可以在将矩阵发送到 repmat

之前转置它
> repmat(t(b), 3, 1)
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6
[3,] 1 3 5
[4,] 2 4 6
[5,] 1 3 5
[6,] 2 4 6

关于R matlab 包 : why is repmat inconsistent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16360377/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com