def shrink_sr(sr, layers):
    """Shrink SR by the given number of layers.

    Parameters
    ----------
    sr : numpy.ndarray
        the boolean 2D array to be shrunk
    layers : int
        number of layers to shrink

    Returns
    -------
    numpy.ndarray
        An array of the same shape as the input, with the SR shrunk.
    """
    assert len(sr.shape) == 2, "expected 2D array"
    shrunk = sr.copy()
    for i in range(1, layers+1):
        shrunk[i:, :] *= sr[:-i, :]
        shrunk[:-i, :] *= sr[i:, :]
        shrunk[:, i:] *= sr[:, :-i]
        shrunk[:, :-i] *= sr[:, i:]
    return shrunk