I have a 2d matrix which can be any size but always a square. I want to loop through the matrix and for each diagonal element (x in the example) I want to assign the value 1-sum_of_all_other_values_in_the_row e.g.
Mtx = [[ x ,.2 , 0 ,.2,.2]
[ 0 , x ,.4 ,.2,.2]
[.2 ,.2 , x , 0, 0]
[ 0 , 0 ,.2 , x,.2]
[ 0 , 0 , 0 , 0, x]]
for i in enumerate(Mtx):
for j in enumerate(Mtx):
if Mtx[i][j] == 'x'
Mtx[i][j] = 1-sum of all other [j]'s in the row
I can’t figure out how to get the sum of the j’s in each row
1 Answer