kdb+q-lang

Take a column of a matrix and make it a row in kdb


Consider the matrix:

1 2 3
4 5 6
7 8 9 

I'd like to take the middle column, assign it to a variable, and replace the middle row with it, giving me

1 2 3
2 5 8
7 8 9 

I'm extracting the middle column using

a:m[;enlist1]

which returns

2
5
8

How do I replace the middle row with a? Is a flip necessary?

Thanks.


Solution

  • You can use dot amend -

    q)show m:(3;3)#1+til 10
        1 2 3
        4 5 6
        7 8 9
    q)show a:m[;1]
        2 5 8
    q).[m;(1;::);:;a]
        1 2 3
        2 5 8
        7 8 9
    

    Can see documentation here: