# iteration of a matrix

Hello community,

I have the following question. I have a matrix defined as K. And its diagonal defined, for instance, as `z = [1, 2, 3, 4, 5]`

. I need to change each entry of a diagonal one by one, and then check a condition using 'if' statement. For example, change z to `[2, 2, 3, 4, 5]`

and then `[1, 3, 3, 4, 5]`

and then `[1, 2, 4, 4, 5]`

(increasing each element by 1)

Now I have a code :

```
for i in range(16):
K1 = K
K1[i,i] = K[i,i] + 1
V1 = p1 * K1 * p1t
V2 = p2 * K1 * p2t
if V2 < V1:
print i
```

So the first three rows are more interesting for the problem. The problem is, this code changes each entry, not returning the previous one to the initial position. So it changes the diagonal as following: `[1, 2, 3, 4, 5]`

to `[2, 2, 3, 4, 5]`

to `[2, 3, 3, 4, 5]`

to `[2, 3, 4, 4, 5]`

etc. How can I modify this code to correct the problem? Thank you.