a triangular matrix:
q)show x</:til 5
01111b
00111b
00011b
00001b
00000b
instead of setting the triangle to 1s, what formula sets the triangle to 0 1 2 .. ?
eg
0 0 1 2 3
0 0 4 5 6
0 0 0 7 8
0 0 0 0 9
0 0 0 0 0
a triangular matrix:
q)show x</:til 5
01111b
00111b
00011b
00001b
00000b
instead of setting the triangle to 1s, what formula sets the triangle to 0 1 2 .. ?
eg
0 0 1 2 3
0 0 4 5 6
0 0 0 7 8
0 0 0 0 9
0 0 0 0 0
Hey effbiae, this hopefully should do what you’re looking for. It flattens the matrix and checks where the values are not 0, and replaces them with the values up to 10.
Would need slight modification/parameters passed through if creating different sized matrices.
q) {(t(&:)((t:“i”$(,/)[x</:til 5])>0)):til 10;:5 cut t}
0 0 1 2 3
0 0 4 5 6
0 0 0 7 8
0 0 0 0 9
0 0 0 0 0
Kind regards,
Matt
i had {(sums y)+y*last x}[0;x</:til 5]
which isn’t very fast
and needs this dmend to produce the example:
{(sums y)+y*last x}[0;.[x</:til 5;0 1;:;0b]]