I'm doing some calculation in python and I have to sum items from a list, if they are on the list. This is the code:
Ei=-J*S[i][j]*(S[i+1][j]+S[i-1][j]+S[i][j+1]+S[i][j-1])
what I want is to make zero the value of the element that gives the error list index out of range
. Is there a way to do this without verifying if every element of the sum exists?
thanks in advance
Edit
I don't want the sum to be 0, only the element that gives the error