I have a numpy array that looks like this:
[[1399 17 4 3 0 0 0 0]
[ 11 374 2 3 1 4 0 1]
[ 7 0 187 4 0 0 1 1]
[ 2 3 4 308 0 0 0 3]
[ 2 0 0 0 280 3 0 1]
[ 0 2 0 0 2 81 0 3]
[ 1 0 2 0 2 0 154 4]
[ 0 0 1 2 1 1 8 552]]
I want to replace the values where [x,x] that is the column and row number are the same, to np.nan. I have tried doing this:
for i in range(8):
data[i][i] = np.nan
but it gives an error
Many thanks