sub identity-matrix($n) {
my @id;
for flat ^$n X ^$n -> $i, $j {
@id[$i][$j] = +($i == $j);
}
@id;
}
.say for identity-matrix(5);
[1 0 0 0 0]
[0 1 0 0 0]
[0 0 1 0 0]
[0 0 0 1 0]
[0 0 0 0 1]
sub identity-matrix($n) {
my @id = [0 xx $n] xx $n;
@id[$_][$_] = 1 for ^$n;
@id;
}
sub identity-matrix($n) {
[1, |(0 xx $n-1)], *.rotate(-1) ... *[*-1]
}