I have two lists of vectors and I want to take the outer product between elements in the lists of the same index. Using either Outer or TensorProduct works for e.g. the first two indices:

 a = {{a1, a2, a3}, {b1, b2, b3}};
 b = {{e1, e2, e3}, {f1, f2, f3}};
 MatrixForm[Outer[Times, a[[1]], b[[1]]]]
 MatrixForm[TensorProduct[a[[1]], b[[1]]]]
 MatrixForm[Outer[Times, a[[2]], b[[2]]]]
 MatrixForm[TensorProduct[a[[2]], b[[2]]]]

I would like a command that can do this for lists of Length 1000 where the data is imported as a Table as follows and where All = 1000 :

vectorData = Import["/home/vectorData", "Table"];
a = vectorData[[All, {2, 3, 4}]];
b = vectorData[[All, {5, 6, 7}]];

I had a similar question in mind for inner products between "lists of vectors" (or tensors) but this was solved neatly with MapThread : MapThread[Dot, {a, b}]. Does anyone have a similar technique for the outer products ?


You can use MapThread with TensorProduct as the first argument as follows:

MapThread[TensorProduct, {a, b}]

{{{a1 e1, a1 e2, a1 e3}, {a2 e1, a2 e2, a2 e3}, {a3 e1, a3 e2, a3 e3}},
{{b1 f1, b1 f2, b1 f3}, {b2 f1, b2 f2, b2 f3}, {b3 f1, b3 f2, b3 f3}}}

TeXForm[MatrixForm /@ %]

$\left\{\left( \begin{array}{ccc} \text{a1} \text{e1} & \text{a1} \text{e2} & \text{a1} \text{e3} \\ \text{a2} \text{e1} & \text{a2} \text{e2} & \text{a2} \text{e3} \\ \text{a3} \text{e1} & \text{a3} \text{e2} & \text{a3} \text{e3} \\ \end{array} \right),\left( \begin{array}{ccc} \text{b1} \text{f1} & \text{b1} \text{f2} & \text{b1} \text{f3} \\ \text{b2} \text{f1} & \text{b2} \text{f2} & \text{b2} \text{f3} \\ \text{b3} \text{f1} & \text{b3} \text{f2} & \text{b3} \text{f3} \\ \end{array} \right)\right\}$

| improve this answer | |
  • $\begingroup$ This works perfectly. I'm not (yet) reputable enough to thank you, or at least to visibly thank you! But I'll come back when I am. $\endgroup$ – AshaEgreck May 27 '19 at 18:15

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.