title: How to calculate the balancing of a matrix in python?
body: <p>I would like to perform a <a href="https://strathprints.strath.ac.uk/42589/1/fastbalance.pdf" rel="nofollow noreferrer">matrix balancing</a> in python. I thought to use <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.matrix_balance.html" rel="nofollow noreferrer"><code>linalg.matrix_balance</code></a> in order to make the input matrix a <a href="https://en.wikipedia.org/wiki/Doubly_stochastic_matrix" rel="nofollow noreferrer">doubly stochastic matrix</a>:</p>
  
  <pre><code>from scipy import linalg
  import numpy as np
  x = np.array([[1,2,7], [9,1,1], [1,2,10*np.pi]])
  
  y, permscale = linalg.matrix_balance(x)    
  np.abs(x).sum(axis=0) / np.abs(x).sum(axis=1)        
  np.abs(y).sum(axis=0) / np.abs(y).sum(axis=1)
  
  
  permscale  
  
  array([[ 1.,  0.,  0.],
        [ 0.,  2.,  0.],
        [ 0.,  0.,  1.]])
  </code></pre>
  
  <p>It doesn't look that it actually balancing the rows and cols of the matrix. Any idea what should I do? </p>
  
  <p>If I do: <code>y, permscale = linalg.matrix_balance(x, scale=False)</code></p>
  
  <p>The result isn't normalized either: </p>
  
  <pre><code>array([[ 1. , 2. , 7. ], [ 9. , 1. , 1. ], [ 1. , 2. , 31.41592654]])
  </code></pre>