Skip to content

Instantly share code, notes, and snippets.

@timtrueman
Created February 9, 2010 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timtrueman/298938 to your computer and use it in GitHub Desktop.
Save timtrueman/298938 to your computer and use it in GitHub Desktop.
Python — Use the curses library to display a numpy matrix in a pretty manner
def display_matrix(screen, m, x, y, precision=2, title=None):
rows, cols = m.shape
if title:
screen.addstr(x, y, title)
x += 1
screen.addstr(x, y, "[")
screen.addstr(x, cols*(4+precision)+y+1, "]")
screen.addstr(rows+x-1, y, "[")
screen.addstr(rows+x-1, cols*(4+precision)+y+1, "]")
for row in range(rows):
for col in range(cols):
screen.addstr(row+x, col*(4+precision)+y+1, "%+.*f," % (precision, m[row, col]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment