Skip to main content

Looking for an elegant way to construct this tensor-product-ish list



I would like to make the following matrix:


{
{{1, 13}, {1, 14}, {1, 15}, {1, 16}, {2, 13}, {2, 14}, {2, 15},{2, 16}, ...,
{32, 13}, {32, 14}, {32, 15}, {32, 16}},
{{1, 9}, {1, 10}, {1, 11}, {1, 12}, {2, 9}, {2, 10}, {2, 11}, {2, 12}, ...,
{32, 9}, {32, 10}, {32, 11}, {32, 12}},
...
{{1, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 1}, {2, 2}, {2, 3},{2, 4}, ...,
{32, 1}, {32, 2}, {32, 3}, {32, 4}}
}


I'd like to make this out of these two things:


A = {Range[13, 16], Range[9, 12], Range[5, 8], Range[4]}

and


B = Range[32]

In other words, I'd like to glue copies of A all in a row with each entry indexed by B.


Is there a good way to do this?



Answer




You could do this:


Outer[List, B, #] & /@ A

Comments