如何在raku-lang中操作连接两个矩阵?
How to operator join two matrix in raku-lang?
ruku中有没有类似R语言的column bind和rbind之类的东西。
R-lang cbind
例如
my @matrix = ^100 .rotor(10);
my @cbind = cbind( @matrix [*;1..2].rotor(2) , @matrix [*;3..4].rotor(2) )
my @rbind = rbind ( @matrix [1..2;*].rotor(10) , @matrix [3..4;*].rotor(10) )
rbind
很简单:
my @one = <a b c d>.rotor(2);
my @two = <e f g h>.rotor(2);
say @one.append: @two;
更新:已编辑感谢评论。
If order does not matter so much, you can just use ∪ and it will turn into a set.
cbind
有点棘手,但可行:
say (@one Z @two).map( { @_.map: |* } )
Z
是 zip 运算符,它将交错第一个和第二个列表的元素。但是嵌套列表太多了,所以我们需要在此处展平内部列表:{ @_.map: |* }
。这将输出
((a b e f) (c d g h))
ruku中有没有类似R语言的column bind和rbind之类的东西。 R-lang cbind
例如
my @matrix = ^100 .rotor(10);
my @cbind = cbind( @matrix [*;1..2].rotor(2) , @matrix [*;3..4].rotor(2) )
my @rbind = rbind ( @matrix [1..2;*].rotor(10) , @matrix [3..4;*].rotor(10) )
rbind
很简单:
my @one = <a b c d>.rotor(2);
my @two = <e f g h>.rotor(2);
say @one.append: @two;
更新:已编辑感谢评论。
If order does not matter so much, you can just use ∪ and it will turn into a set.
cbind
有点棘手,但可行:
say (@one Z @two).map( { @_.map: |* } )
Z
是 zip 运算符,它将交错第一个和第二个列表的元素。但是嵌套列表太多了,所以我们需要在此处展平内部列表:{ @_.map: |* }
。这将输出
((a b e f) (c d g h))