Streamlined version of matplotlib's `xcorr`, without the plots.

    :param x, y: NumPy arrays to cross-correlate
    :param maxlags: Max number of lags; result will be `2*maxlags+1` in length

def xcorr(x, y, maxlags):
    """
    Streamlined version of matplotlib's `xcorr`, without the plots.

    :param x, y: NumPy arrays to cross-correlate
    :param maxlags: Max number of lags; result will be `2*maxlags+1` in length
    """
    xlen = len(x)
    ylen = len(y)
    assert xlen == ylen

    c = np.correlate(x, y, mode=2)

    # normalize
    c /= np.sqrt(np.dot(x, x) * np.dot(y, y))

    lags = np.arange(-maxlags, maxlags + 1)
    c = c[xlen - 1 - maxlags:xlen + maxlags]

    return c