title: How can I produce a nice output of a numpy matrix?
body: <p>I currently have the following snippet:</p>
  
  <pre><code>#!/usr/bin/python
  # -*- coding: utf-8 -*-
  
  import numpy
  from numpy import linalg
  
  A = [[1,2,47,11],[3,2,8,15],[0,0,3,1],[0,0,8,1]]
  S = [[113,49,2,283],[-113,0,3,359],[0,5,0,6],[0,20,0,12]]
  
  A = numpy.matrix(A)
  S = numpy.matrix(S)
  
  numpy.set_printoptions(precision=2, suppress=True, linewidth=120)
  print("S^{-1} * A * S")
  print(linalg.inv(S) * A * S)
  </code></pre>
  
  <p>which produces this output:</p>
  
  <p><img src="https://i.stack.imgur.com/QQQjK.png" alt="python output"></p>
  
  <p><strong>Is there a standard way to produce an output similar to the following? How can I get this output?</strong></p>
  
  <pre><code>[[ -1    -0.33  0  0]
   [  0     1     0  0]
   [  0  -648     4  0]
   [  0     6.67  0  5]]
  </code></pre>
  
  <p>What's different?</p>
  
  <ul>
  <li>At least two spaces between the last character of column <code>i</code> and the first character of column <code>i+1</code>, but it might be more if more is needed (NumPy output makes two spaces)</li>
  <li>the dots are aligned (The <em>are</em> aligned, but the font setting of <code>BetterPythonConsole</code> messes it up)</li>
  <li>No <code>-0</code> but <code>0</code></li>
  <li>No <code>0.</code> but <code>0</code></li>
  </ul>
  
  <p><strong>edit</strong>: It seems as if the Python Console, which gets started with gEdits <a href="https://live.gnome.org/Gedit/Plugins/BetterPythonConsole" rel="noreferrer">BetterPythonConsole</a> plugin does something different than Python, when I start it from terminal.</p>
  
  <p>This is the output as text of the script above</p>
  
  <pre><code>moose@pc07:~/Desktop$ python matrixScript.py 
  S^{-1} * A * S
  [[  -1.     -0.33    0.     -0.  ]
   [   0.     -1.     -0.      0.  ]
   [   0.   -648.      4.     -0.  ]
   [   0.      6.67    0.      5.  ]]
  </code></pre>
  
  <p>With prettyprint:</p>
  
  <pre><code>S^{-1} * A * S
  matrix([[  -1.  ,   -0.33,    0.  ,   -0.  ],
          [   0.  ,   -1.  ,   -0.  ,    0.  ],
          [   0.  , -648.  ,    4.  ,   -0.  ],
          [   0.  ,    6.67,    0.  ,    5.  ]])
  </code></pre>
  
  <p>This is defenitely worse, but it was worth a try.</p>