Imagine that I want to take the numbers from 1 to 3 and form a matrix such that each possible pairing is represented, e.g.,
1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3
Here is the monadic verb I formulated in J to do this:
($~ (-:@# , 2:)) , ,"0/~ 1+i.y
Originally I had thought that ,"0/~ 1+i.y
would be sufficient, but unfortunately that produces the following output:
1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3
In other words, its shape is 3 3 2 and I want something whose shape is 9 2. The only way I could think of to fix it is to pour all of the data into a new shape. I'm convinced there must be a more concise way to do this. Anyone know?