def _modified_weiszfeld_step(X, x_old):
 diff = (X - x_old)
 diff_norm = np.sqrt(np.sum((diff ** 2), axis=1))
 mask = (diff_norm >= _EPSILON)
 is_x_old_in_X = int((mask.sum() < X.shape[0]))
 diff = diff[mask]
 diff_norm = diff_norm[mask][:, np.newaxis]
 quotient_norm = linalg.norm(np.sum((diff / diff_norm), axis=0))
 if (quotient_norm > _EPSILON):
  new_direction = (np.sum((X[mask, :] / diff_norm), axis=0) / np.sum((1 / diff_norm), axis=0))
 else:
  new_direction = 1.0
  quotient_norm = 1.0
 return ((max(0.0, (1.0 - (is_x_old_in_X / quotient_norm))) * new_direction) + (min(1.0, (is_x_old_in_X / quotient_norm)) * x_old))

def _modified_weiszfeld_step ( X , x_old ) : diff = ( X - x_old ) diff_norm = np . sqrt ( np . sum ( ( diff ** 2 ) , axis = 1 ) ) mask = ( diff_norm >= _EPSILON ) is_x_old_in_X = int ( ( mask . sum ( ) < X . shape [ 0 ] ) ) diff = diff [ mask ] diff_norm = diff_norm [ mask ] [ : , np . newaxis ] quotient_norm = linalg . norm ( np . sum ( ( diff / diff_norm ) , axis = 0 ) ) if ( quotient_norm > _EPSILON ) : new_direction = ( np . sum ( ( X [ mask , : ] / diff_norm ) , axis = 0 ) / np . sum ( ( 1 / diff_norm ) , axis = 0 ) ) else : new_direction = 1.0 quotient_norm = 1.0 return ( ( max ( 0.0 , ( 1.0 - ( is_x_old_in_X / quotient_norm ) ) ) * new_direction ) + ( min ( 1.0 , ( is_x_old_in_X / quotient_norm ) ) * x_old ) )
modified weiszfeld step .