I have the following routine where I build a pair of function name lists {Flist, Klist}
and 1D argument list {a1,a2,a3,a4,a5}
:
T = Transpose@{ToExpression@ Table[StringJoin["a", ToString[i]], {i, 1, 5}]};
Flist = {F1, F2, F3};
Klist = {K1, K2, K3};
Flatten[Outer[{#1, #2} &, {Flist, Klist}, T], 3]
Out[149]= {{F1, a1}, {F1, a2}, {F1, a3}, {F1, a4}, {F1, a5},
{F2, a1}, {F2, a2}, {F2, a3}, {F2, a4}, {F2, a5},
{F3, a1}, {F3, a2}, {F3, a3}, {F3, a4}, {F3, a5},
{K1, a1}, {K1, a2}, {K1, a3}, {K1, a4}, {K1, a5},
{K2, a1}, {K2, a2}, {K2, a3}, {K2, a4}, {K2, a5},
{K3, a1}, {K3, a2}, {K3, a3}, {K3, a4}, {K3, a5}}
With the one argument or many, e.g. {Fn, arg1_n, arg2_n}
, it works, but I am confused with the Outer
function applied to the nested lists as to:
T = Transpose@{ToExpression@Table[StringJoin["a", ToString[i]], {i, 1, 5}],ToExpression@Table[StringJoin["b", ToString[i]], {i, 1, 5}]}
Out[151]= {{a1, b1}, {a2, b2}, {a3, b3}, {a4, b4}, {a5, b5}}
Flatten[Outer[{#1, #2} &, {Flist, Klist}, T, 1], 1]
Out[182]= {{{F1, F2, F3, F4, F5}, {a1, b1}}, {{F1, F2, F3, F4,
F5}, {a2, b2}}, {{F1, F2, F3, F4, F5}, {a3, b3}}, {{F1, F2, F3, F4,
F5}, {a4, b4}}, {{F1, F2, F3, F4, F5}, {a5, b5}}, {{K1, K2, K3,
K4, K5}, {a1, b1}}, {{K1, K2, K3, K4, K5}, {a2, b2}}, {{K1, K2, K3,
K4, K5}, {a3, b3}}, {{K1, K2, K3, K4, K5}, {a4, b4}}, {{K1, K2,
K3, K4, K5}, {a5, b5}}}
I played with dimensions allowed in Outer
and Flatten
and did not succeeded to obtain result in the following form:
{{F1, {a1, b1}}, {F1, {a2,b2}}, {F1, {a3,b3}},.......
{K3, {a3, b3}}, {K3, {a4, a4}}, {K3, {a5, b5}}}
Can someone advise how to obtained desired output having {Flist, Klist}
and nested list T
?
UPD Fr
and Kr
which @lericr asked below, was a typo in my code, which I fixed and recall them Klist
and Klist
. Sorry for omission.
Fr
andKr
? $\endgroup$Fr
must be{F1, F2, F3, F4, F5}
and similarly forKr
. $\endgroup$Flatten[Outer[List, Join[Fr, Kr], T, 1], 1]
$\endgroup$Fr' and 'Kr' are supposed to be
Flist` and Klist` I did a mistake in the code. $\endgroup$