def normalize_dense(M, norm="<STR_LIT>", order=<NUM_LIT:1>, iterations=<NUM_LIT:3>):
s = np.array(M, np.float64)<EOL>floatorder = np.float64(order)<EOL>if norm == "<STR_LIT>":<EOL><INDENT>for _ in range(<NUM_LIT:0>, iterations):<EOL><INDENT>sumrows = s.sum(axis=<NUM_LIT:1>)<EOL>maskrows = (sumrows != <NUM_LIT:0>)[:, None] * (sumrows != <NUM_LIT:0>)[None, :]<EOL>sums_row = sumrows[:, None] * np.ones(sumrows.shape)[None, :]<EOL>s[maskrows] = <NUM_LIT:1.> * s[maskrows] / sums_row[maskrows]<EOL>sumcols = s.sum(axis=<NUM_LIT:0>)<EOL>maskcols = (sumcols != <NUM_LIT:0>)[:, None] * (sumcols != <NUM_LIT:0>)[None, :]<EOL>sums_col = sumcols[None, :] * np.ones(sumcols.shape)[:, None]<EOL>s[maskcols] = <NUM_LIT:1.> * s[maskcols] / sums_col[maskcols]<EOL><DEDENT><DEDENT>elif norm == "<STR_LIT>":<EOL><INDENT>try:<EOL><INDENT>from mirnylib import numutils as ntls<EOL>s = ntls.iterativeCorrection(s, iterations)[<NUM_LIT:0>]<EOL><DEDENT>except ImportError as e:<EOL><INDENT>print(str(e))<EOL>print("<STR_LIT>")<EOL>print("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>print("<STR_LIT>")<EOL>return normalize_dense(M, order=order, iterations=iterations)<EOL><DEDENT><DEDENT>elif norm == "<STR_LIT>":<EOL><INDENT>for _ in range(<NUM_LIT:1>, iterations):<EOL><INDENT>s_norm_x = np.linalg.norm(s, ord=floatorder, axis=<NUM_LIT:0>)<EOL>s_norm_y = np.linalg.norm(s, ord=floatorder, axis=<NUM_LIT:1>)<EOL>s_norm = np.tensordot(s_norm_x, s_norm_y, axes=<NUM_LIT:0>)<EOL>s[s_norm != <NUM_LIT:0>] = <NUM_LIT:1.> * s[s_norm != <NUM_LIT:0>] / s_norm[s_norm != <NUM_LIT:0>]<EOL><DEDENT><DEDENT>elif norm == "<STR_LIT>":<EOL><INDENT>s_norm = np.linalg.norm(s, ord=floatorder)<EOL>s /= <NUM_LIT:1.> * s_norm<EOL><DEDENT>elif callable(norm):<EOL><INDENT>s = norm(M)<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>return (s + s.T) / <NUM_LIT:2><EOL>
Apply one of the many normalization types to input dense
    matrix. Will also apply any callable norms such as a user-made
    or a lambda function.