def _weight_func(dist):
 with np.errstate(divide='ignore'):
  retval = (1.0 / dist)
 return (retval ** 2)

def _weight_func ( dist ) : with np . errstate ( divide = 'ignore' ) : retval = ( 1.0 / dist ) return ( retval ** 2 )
weight function to replace lambda d: d ** -2 .