Created
February 9, 2010 05:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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