How to create a list of pairs from 1d list(s)?
As to question 1
Subsets[A, {2}]
Gives
{{1, 2}, {1, 3}, {2, 3}}
As to question 2
Tuples[{A, B}]
Gives
{{1, a}, {1, b}, {1, c}, {2, a}, {2, b}, {2, c}, {3, a}, {3, b}, {3,
c}}
Question 1 with dupes:
Tuples[A, {2}]
Gives
{{1, 1}, {1, 2}, {1, 3}, {2, 1}, {2, 2}, {2, 3}, {3, 1}, {3, 2}, {3,
3}}
You can see this also includes {1, 1}
. If all you want is the same result as before but reversed, you can do Join[#, Reverse/@#]&@Subsets[A, {2}]
or use Permutations[A, {2}]
@EliLansey suggested in his answer
Question 2 with duples, I'm not sure what you mean. Perhaps Tuples[{A, B}]~Join~Tuples[{B, A}]
(or, equivalently, Join[#, Reverse/@#]&@Tuples[{A, B}]
) ?
Here's an answer for a variant of question #2 for those who were looking for something slightly different, as I was.
The original question #2 is asking for a generalized outer product (matching up every element of the first list with every element of the second list), which is why Artes correctly gives Outer[List, A, B]
as the solution. Here List
is the operator to perform on each pair of elements.
This lead me to solve my own problem, which was to create a generalized inner product list (matching up the i-th element of the first list with the i-th element of the second list), which looks like {{1,a},{2,b},{3,c}}
.
Inner[List, A, B, List]
gives
{{1, a}, {2, b}, {3, c}}
Here, List
replaces both the multiplication and addition functions in the usual inner product.
This is useful if you have two lists for separate 1D histograms that you want to combine into a 2D histogram with Histogram3D
.
Ad. 1
ordering not valid:
Subsets[A, {2}]
{{1, 2}, {1, 3}, {2, 3}}
or with ordering
Permutations[A, {2}]
Ad. 2
Outer[List, A, B]
{{{1, a}, {1, b}, {1, c}}, {{2, a}, {2, b}, {2, c}}, {{3, a}, {3, b}, {3, c}}}
or exactly
Outer[List, A, B] // Flatten[#, 1] &
{{1, a}, {1, b}, {1, c}, {2, a}, {2, b}, {2, c}, {3, a}, {3, b}, {3, c}}