def inf_to_nan(func):
 def wrap(*a, **kw):
  v = func(*a, **kw)
  if (not np.isfinite(v)):
   return np.nan
  return v
 return wrap

def inf_to_nan ( func ) : def wrap ( * a , ** kw ) : v = func ( * a , ** kw ) if ( not np . isfinite ( v ) ) : return np . nan return v return wrap
decorate function to return nan if it returns inf .