Home > Mobile >  How can I replace 1s in one matrix with another sub matrix?
How can I replace 1s in one matrix with another sub matrix?

Time:05-25

I have a matrix-like

[[1, 2],
 [3, 4]]

and I want to replace the 1s in another matrix:

[[1, 0],
 [1, 1]]

to make this matrix:

[[1, 2, 0, 0],
 [3, 4, 0, 0],
 [1, 2, 1, 2],
 [3, 4, 3, 4]]

The 1s in the second matrix can be in any position, this is just an example.

How can I do this?

CodePudding user response:

Use enter image description here

In other words, with the matrix A (or numpy array a) we indicate if the entries of B shall be added (if 1) or not (if 0).

  • Related