def _get_weights(dist, weights):
 if (weights in (None, 'uniform')):
  return None
 elif (weights == 'distance'):
  if (dist.dtype is np.dtype(object)):
   for (point_dist_i, point_dist) in enumerate(dist):
    if (hasattr(point_dist, '__contains__') and (0.0 in point_dist)):
     dist[point_dist_i] = (point_dist == 0.0)
    else:
     dist[point_dist_i] = (1.0 / point_dist)
  else:
   with np.errstate(divide='ignore'):
    dist = (1.0 / dist)
   inf_mask = np.isinf(dist)
   inf_row = np.any(inf_mask, axis=1)
   dist[inf_row] = inf_mask[inf_row]
  return dist
 elif callable(weights):
  return weights(dist)
 else:
  raise ValueError("weights not recognized: should be 'uniform', 'distance', or a callable function")

def _get_weights ( dist , weights ) : if ( weights in ( None , 'uniform' ) ) : return None elif ( weights == 'distance' ) : if ( dist . dtype is np . dtype ( object ) ) : for ( point_dist_i , point_dist ) in enumerate ( dist ) : if ( hasattr ( point_dist , '__contains__' ) and ( 0.0 in point_dist ) ) : dist [ point_dist_i ] = ( point_dist == 0.0 ) else : dist [ point_dist_i ] = ( 1.0 / point_dist ) else : with np . errstate ( divide = 'ignore' ) : dist = ( 1.0 / dist ) inf_mask = np . isinf ( dist ) inf_row = np . any ( inf_mask , axis = 1 ) dist [ inf_row ] = inf_mask [ inf_row ] return dist elif callable ( weights ) : return weights ( dist ) else : raise ValueError ( "weights not recognized: should be 'uniform', 'distance', or a callable function" )
get the weights from an array of distances and a parameter weights parameters dist : ndarray the input distances weights : {uniform .