1
$\begingroup$

There is a large list, with $n$ sublists of the same length (e.g. length is 3).

list1 = {{a_1, b_1, c_1}, {a_2, b_2, c_2},..., {a_n, b_n, c_n}}

If I need to regard $n$ as a parameter, how can I get the general expression of the outer product of the sublists?

Maybe we need to make some change to the code like this?

Outer[List, list1[[1]], list1[[2]], ...., list1[[n]], 1]

Should we use loop? or there will be better method?

$\endgroup$
2
  • 1
    $\begingroup$ try Outer[List, Sequence @@ list1]? $\endgroup$
    – kglr
    Sep 22 '21 at 16:02
  • $\begingroup$ Also, I notice you're using Outer[List, ...]; just in case you plan to flatten this outer product, note the existence of Tuples[list1] $\endgroup$
    – thorimur
    Sep 22 '21 at 21:07
1
$\begingroup$

Define a function that generates a suitable list of triplets:

lists[n_] := Array[a[#1][#2] &, {n, 3}]

lists[2]
(* {{a[1][1], a[1][2], a[1][3]}, {a[2][1], a[2][2], a[2][3]}} *)

We can apply Outer to such a list e.g.

Outer[Times, ##] & @@ lists[2]
(* {{a[1][1] a[2][1], a[1][1] a[2][2], 
  a[1][1] a[2][3]}, {a[1][2] a[2][1], a[1][2] a[2][2], 
  a[1][2] a[2][3]}, {a[1][3] a[2][1], a[1][3] a[2][2], 
  a[1][3] a[2][3]}} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.