I am trying to set all the elements in the principal diagonal of the matrix to be equal to one. Here is my code for the same, using a matrix named "a":
for i in range(len(a)):
a[i][i] = 1
However, this is setting all elements in a to be 1. I found out that this is because the call a[i][i] is accessing the entire i'th row and not the i'th diagonal element. How do I modify the code to have the intended effect?