0

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)

Will Da Silva
  • 6,386
  • 2
  • 27
  • 52
codeforkdb
  • 13
  • 1
  • 9

2 Answers2

3

Joining the two vectors using the each (each-both in this case) iterator returns your desired output.

q)0N!A,'B
(0 3;1 4;2 5)
0 3
1 4
2 5
Cathal O'Neill
  • 2,522
  • 1
  • 6
  • 17
2

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
drgdavies
  • 81
  • 3