def distance_law(matrix, log_bins=False):
D = np.array([np.average(np.diagonal(matrix, j))<EOL>for j in range(min(matrix.shape))])<EOL>if not log_bins:<EOL><INDENT>return D<EOL><DEDENT>else:<EOL><INDENT>n = min(matrix.shape)<EOL>n_bins = int(np.log(n) / np.log(<NUM_LIT:2>) + <NUM_LIT:1>)<EOL>logD = np.array([np.average(D[int(<NUM_LIT:2>**(i - <NUM_LIT:1>)):min(n, <NUM_LIT:2>**i)])<EOL>for i in range(n_bins)])<EOL>return logD<EOL><DEDENT>
Compute distance law as a function of the genomic coordinate aka P(s).
    Bin length increases exponentially with distance if log_bins is True.