def bin_kb_dense(M, positions, length=<NUM_LIT:10>, contigs=None):
unit = <NUM_LIT:10>**<NUM_LIT:3><EOL>ul = unit * length<EOL>unit = positions / ul<EOL>n = len(positions)<EOL>idx = [i for i in range(<EOL>n - <NUM_LIT:1>) if np.ceil(unit[i]) < np.ceil(unit[i + <NUM_LIT:1>])]<EOL>binned_positions = positions[idx]<EOL>m = len(idx) - <NUM_LIT:1><EOL>N = np.zeros((m, m))<EOL>for i in range(m):<EOL><INDENT>N[i] = np.array([M[idx[j]:idx[j + <NUM_LIT:1>], idx[i]:idx[i + <NUM_LIT:1>]].sum()<EOL>for j in range(m)])<EOL><DEDENT>return N, binned_positions<EOL>
Perform binning with a fixed genomic length in
    kilobase pairs (kb). Fragments will be binned such
    that their total length is closest to the specified input.
    If a contig list is specified, binning will be performed
    such that fragments never overlap two contigs.