def _spatial_median(X, max_iter=300, tol=0.001):
 if (X.shape[1] == 1):
  return (1, np.median(X.ravel()))
 tol **= 2
 spatial_median_old = np.mean(X, axis=0)
 for n_iter in range(max_iter):
  spatial_median = _modified_weiszfeld_step(X, spatial_median_old)
  if (np.sum(((spatial_median_old - spatial_median) ** 2)) < tol):
   break
  else:
   spatial_median_old = spatial_median
 else:
  warnings.warn('Maximum number of iterations {max_iter} reached in spatial median for TheilSen regressor.'.format(max_iter=max_iter), ConvergenceWarning)
 return (n_iter, spatial_median)

def _spatial_median ( X , max_iter = 300 , tol = 0.001 ) : if ( X . shape [ 1 ] == 1 ) : return ( 1 , np . median ( X . ravel ( ) ) ) tol **= 2 spatial_median_old = np . mean ( X , axis = 0 ) for n_iter in range ( max_iter ) : spatial_median = _modified_weiszfeld_step ( X , spatial_median_old ) if ( np . sum ( ( ( spatial_median_old - spatial_median ) ** 2 ) ) < tol ) : break else : spatial_median_old = spatial_median else : warnings . warn ( 'Maximum number of iterations {max_iter} reached in spatial median for TheilSen regressor.' . format ( max_iter = max_iter ) , ConvergenceWarning ) return ( n_iter , spatial_median )
spatial median .