def print_matrix(m, rownames, colnames):
    """Pretty-print a 2d numpy array with row and column names."""
    # Max column width:
    col_width = max([len(x) for x in rownames + colnames]) + 4
    # Row-formatter:
    def fmt_row(a):
        return "".join(map((lambda x : str(x).rjust(col_width)), a))
    # Printing:
    print(fmt_row([''] + colnames))            
    for i, rowname in enumerate(rownames):
        row = [rowname]
        for j in range(len(colnames)):
            row.append(round(m[i, j], 2))
        print(fmt_row(row))