def bin_dense(M, subsampling_factor=<NUM_LIT:3>):
m = min(M.shape)<EOL>n = (m // subsampling_factor) * subsampling_factor<EOL>if n == <NUM_LIT:0>:<EOL><INDENT>return np.array([M.sum()])<EOL><DEDENT>N = np.array(M[:n, :n], dtype=np.float64)<EOL>N = N.reshape(n // subsampling_factor, subsampling_factor,<EOL>n // subsampling_factor, subsampling_factor).sum(axis=(<NUM_LIT:1>, <NUM_LIT:3>))<EOL>if m > n:<EOL><INDENT>remaining_row = M[n:, :n]<EOL>remaining_col = M[:n, n:]<EOL>remaining_square = M[n:m, n:m]<EOL>R = remaining_row.reshape(m % subsampling_factor,<EOL>m // subsampling_factor,<EOL>subsampling_factor).sum(axis=(<NUM_LIT:0>, <NUM_LIT:2>))<EOL>C = remaining_col.T.reshape(m % subsampling_factor,<EOL>m // subsampling_factor,<EOL>subsampling_factor).sum(axis=(<NUM_LIT:0>, <NUM_LIT:2>)).T<EOL>S = remaining_square.sum()<EOL>N = np.append(N, [R], axis=<NUM_LIT:0>)<EOL>result = np.append(N, np.array([list(C) + [S]]).T, axis=<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>result = N<EOL><DEDENT>return result<EOL>
Sum over each block of given subsampling factor, returns a matrix whose
    dimensions are this much as small (e.g. a 27x27 matrix binned with a
    subsampling factor equal to 3 will return a 9x9 matrix whose each component
    is the sum of the corresponding 3x3 block in the original matrix).
    Remaining columns and rows are summed likewise and added to the end of the
    new matrix.

    :note: Will not work for numpy verisons below 1.7