I was expecting to avoid the cancelling problem by using the square of the distances, and at the end try to compute the trace of the Hessian matrix at each node but I might be missing something.
Also, if the gradients were to cancel, wouldn’t I get also zero for the first gradient computation? I’m obtaining:
[[ 4.,  4.,  4.],
[-6.,  2.,  2.],
[ 2., -6.,  2.],
[ 2.,  2., -6.],
[-2., -2., -2.]]