Created
January 31, 2015 21:36
-
-
Save austensatterlee/5e23414f5e6243d1fea5 to your computer and use it in GitHub Desktop.
Handy Python
This file contains hidden or 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 print_matrix(mat,rvalues=None,cvalues=None): | |
# print a 2d numpy array as a table, using the optional rvalues | |
# and cvalues as row and column labels | |
if rvalues==None: | |
rvalues=np.arange(mat.shape[0]) | |
if cvalues==None: | |
cvalues=np.arange(mat.shape[1]) | |
print ("{:5}"+"{:^6} "*mat.shape[1]).format('',*cvalues) | |
print ("{:5}"+"{:^6} "*mat.shape[1]).format('',*["-----" for i in cvalues]) | |
for i,r in enumerate(rvalues): | |
print ("{:4}|"+"{:^6.2f}|"*mat.shape[1]).format(r,*mat[i-1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment