# Replace Table with a fast matrix operation to create for matrices A, B the tensor (b_{ij}A) and similar questions

I have two (nxn)-matrices A=(a_{ij}) and B=(b_{ij}) and I'd like to create the (nxnxnxn)-List

C=(b_{ij}*A)


so e.g.

SeedRandom["testing"]
bb = ConstantArray[1, {3, 3}];
aa = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
Table[
bb[[i, j]]*aa, {i, 1, 3, 1}, {j, 1, 3, 1}]


I of course can construct it via Table[], see the above code. but it is very slow when we talk about 100x100. I guess theres a trick/possibility via Map[], but it is not

SeedRandom["testing"]
aa = RandomReal[1, {3, 3}]
bb = ConstantArray[1, {3, 3}];
cc = Map[aa, bb]
cc // MatrixForm


Thanks. And I guess a similar question came up, again matrices and vectors

vv = {1, 2, 3}
vvM = Table[
vv[[i]] - vv[[j]], {i, 1, 3, 1}, {j, 1, 3, 1}]
vvM // MatrixForm


Thanks for all the help. Just for information, I think I know Mathematica okayish but when it comes to @, @@, #, stuff like that, I am pretty new to that

• I do not understand your description. Can you please be more explicit about what is the expected value of element $(i,j,k)$ of the resulting matrix $C$? From what you say, $a_{ij}\times B$ is a $n\times n$ matrix for every $(i,j)$, and so you described $C$ is a $n\times n\times n\times n$ matrix (rank-4), not rank-3. Nov 22, 2020 at 11:14
• KroneckerProduct? Nov 22, 2020 at 11:16
• Can you please show how you do it with Table and we will help you to speed it up. At the moment your question is unclear. Nov 22, 2020 at 17:52
• dear Roman and Yarchik, you're totally correct, there's an error. I'll edit the posting and add a similar question, thank you in advance Nov 23, 2020 at 9:26
• Outer[Times, bb, aa] Nov 23, 2020 at 10:12

Maybe your need Outer.
bb = ConstantArray[1, {3, 3}];

vv = {1, 2, 3}