Search code examples
kdb+

Element-wise concatenation of 2 vectors in kdb+


Given 2 vectors A and B, I want to concatenate each element of A with each element of B. For example if A and B were as follows:

A: 0 1 2 
B: 3 4 5 

then the output should be (0 3;1 4; 2 5)


Solution

  • You could also instantiate through the following

    (A;B) to create a 2x3 matrix which can be flipped to get what you require

    q)A:0 1 2
    q)B:3 4 5
    q)(A;B)
    0 1 2
    3 4 5
    q)flip (A;B)
    0 3
    1 4
    2 5