How to apply verb sequentially to vector and each single element of another vector in J

93 views Asked by At

For example I have vector 1 2 3 and vector 4 5 6 and I want to add 1 2 3 and 4 first, then with 5 and then with 6 in the same way, and get 3 vectors 5 6 7, 6 7 8 and 7 8 9.

1

There are 1 answers

2
Eelvex On BEST ANSWER

You need an addition table: +/:

1 2 3 +/ 4 5 6
5 6 7
6 7 8
7 8 9

but by the way you describe what you want, it seems you might prefer a 0-rank addition: +"0:

((1 2 3)&+"0) 4 5 6
5 6 7
6 7 8
7 8 9

The differences are more apparent in asymmetric additions:

1 2 +/ 3 4 5 6
4 5 6 7
5 6 7 8


((1 2)&+"0) 3 4 5 6 
4 5
5 6
6 7
7 8