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

StackOverflow https://stackoverflow.com/questions/20410006

  •  29-08-2022
  •  | 
  •  

Question

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.

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top