3
$\begingroup$

I have this tensor: enter image description here

nn = 4;
tableToFill = 
Table[x, {p, 1, nn}, {q, 1, nn}, {i, 1, nn}, {j, 1, nn}];

that I want to fill with a matrix one by one with a matrix that I get. say the first matrix would be in position 1,1 of the tensor so it would be the top left.

It would look something like this:

enter image description here

I started using a loop but it fills all my matrices with the same numbers.

Do[{tableToFill[[row, col]] = newMatrix
  }, {row, 1, nn}, {col, 1, nn}]
MatrixForm[tableToFill]
$\endgroup$
4
$\begingroup$

Start by generating an array m of the appropriate dimensions. The four by four upper block is the 1,1 element of this, so setting m[[1,1]] to the desired 4 by 4 matrix does the trick.

m = ConstantArray[0, {4, 4, 4, 4}];
m[[1, 1]] = RandomInteger[{1, 10}, {4, 4}]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ works thanks :) $\endgroup$ – user35053 Dec 16 '15 at 23:33

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.