how can i replace element of a matrix based on another matrix of indices?

Do you mean something like this?

I1 = [[3, 1], [4, 3], [2, 3]]
I2 = [[0, 0, 0, 0, 0],
      [0, 0, 0, 0, 0],
      [0, 0, 0, 0, 0],
      [0, 0, 0, 0, 0],
      [0, 0, 0, 0, 0]]

for i, j in I1:
  I2[i][j] = 1

Now I2 will be:

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

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top