def to_dade_matrix(M, annotations="<STR_LIT>", filename=None):
n, m = M.shape<EOL>A = np.zeros((n + <NUM_LIT:1>, m + <NUM_LIT:1>))<EOL>A[<NUM_LIT:1>:, <NUM_LIT:1>:] = M<EOL>if not annotations:<EOL><INDENT>annotations = np.array(["<STR_LIT>" for _ in n], dtype=str)<EOL><DEDENT>A[<NUM_LIT:0>, :] = annotations<EOL>A[:, <NUM_LIT:0>] = annotations.T<EOL>if filename:<EOL><INDENT>try:<EOL><INDENT>np.savetxt(filename, A, fmt='<STR_LIT>')<EOL>print("<STR_LIT>" + str(filename))<EOL><DEDENT>except ValueError as e:<EOL><INDENT>print("<STR_LIT>")<EOL>print(str(e))<EOL><DEDENT>finally:<EOL><INDENT>return A<EOL><DEDENT><DEDENT>return A<EOL>
Returns a Dade matrix from input numpy matrix. Any annotations are added
    as header. If filename is provided and valid, said matrix is also saved
    as text.