def _bistochastic_normalize(X, max_iter=1000, tol=1e-05):
 X = make_nonnegative(X)
 X_scaled = X
 dist = None
 for _ in range(max_iter):
  (X_new, _, _) = _scale_normalize(X_scaled)
  if issparse(X):
   dist = norm((X_scaled.data - X.data))
  else:
   dist = norm((X_scaled - X_new))
  X_scaled = X_new
  if ((dist is not None) and (dist < tol)):
   break
 return X_scaled

def _bistochastic_normalize ( X , max_iter = 1000 , tol = 1e-05 ) : X = make_nonnegative ( X ) X_scaled = X dist = None for _ in range ( max_iter ) : ( X_new , _ , _ ) = _scale_normalize ( X_scaled ) if issparse ( X ) : dist = norm ( ( X_scaled . data - X . data ) ) else : dist = norm ( ( X_scaled - X_new ) ) X_scaled = X_new if ( ( dist is not None ) and ( dist < tol ) ) : break return X_scaled
normalize rows and columns of x simultaneously so that all rows sum to one constant and all columns sum to a different constant .