1
$\begingroup$

I have a two matrix mm and nn. Matrix mm is of dimension 8 cross 8 and nn is of dimensions 4 cross 4. I want to replace the first four rows and columns in mm by nn. How to do this?

mm = ConstantArray[q, {8, 8}]
nn = ConstantArray[r, {4, 4}]
$\endgroup$
1

1 Answer 1

2
$\begingroup$

you can use Table and make any changes you like

Table[mm[[j, k]] = nn[[j, k]], {j, 4}, {k, 4}]   

{{r,r,r,r,q,q,q,q},{r,r,r,r,q,q,q,q},{r,r,r,r,q,q,q,q},{r,r,r,r,q,q,q,q},{q,q,q,q,q,q,q,q},{q,q,q,q,q,q,q,q},{q,q,q,q,q,q,q,q},{q,q,q,q,q,q,q,q}}

$\endgroup$
1
  • $\begingroup$ Do makes more sense here than Table. $\endgroup$
    – Roman
    Commented May 4, 2019 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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