'How do I stack matrices in KDB?
I'm trying to insert a new row at the beginning of a matrix, but the result is inserting my row vector rotated:
a: (.7 .3; .1 .2)
b: (.5 .5)
b, a
0.5
0.5
0.7 0.3
0.1 0.2
Intended result:
0.5 0.5
0.7 0.3
0.1 0.2
What am I doing wrong?
Solution 1:[1]
(enlist b), a gives the result you want. It helps to think of a as being made from nested lists, hence any new rows should be of this form as well.
Solution 2:[2]
Or you can make b a matrix. Join on matrices works the way you expect.
q)(1 2#b),a
0.5 0.5
0.7 0.3
0.1 0.2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | CalumStackenzie |
| Solution 2 | SJT |
