如何在 raku-lang 中对两个矩阵进行运算符连接?

黃家億*_*黃家億 6 r raku

raku 中是否有类似 R-lang 列绑定或行绑定之类的东西。 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) ?
Run Code Online (Sandbox Code Playgroud)

jjm*_*elo 5

rbind 很简单:

my @one = <a b c d>.rotor(2);
my @two = <e f g h>.rotor(2);
say @one.append: @two;
Run Code Online (Sandbox Code Playgroud)

更新:编辑感谢评论。

如果顺序无关紧要,您可以使用 ? 它会变成一个集合。

cbind 有点棘手,但可行:

say (@one Z @two).map( { @_.map: |* } )
Run Code Online (Sandbox Code Playgroud)

Zzip运算符,它将交错第一个和第二个列表的元素。但后来也有太多的嵌套列表,所以我们需要在这里压扁内部列表:{ @_.map: |* }。那将输出

((a b e f) (c d g h))
Run Code Online (Sandbox Code Playgroud)