diff --git a/doc/source/cookbook.rst b/doc/source/cookbook.rst index 21c8ab4128188..df0048c8a74b4 100644 --- a/doc/source/cookbook.rst +++ b/doc/source/cookbook.rst @@ -1234,25 +1234,19 @@ The `method` argument within `DataFrame.corr` can accept a callable in addition n = len(x) a = np.zeros(shape=(n, n)) b = np.zeros(shape=(n, n)) - for i in range(n): for j in range(i + 1, n): a[i, j] = abs(x[i] - x[j]) b[i, j] = abs(y[i] - y[j]) - a += a.T b += b.T - a_bar = np.vstack([np.nanmean(a, axis=0)] * n) b_bar = np.vstack([np.nanmean(b, axis=0)] * n) - A = a - a_bar - a_bar.T + np.full(shape=(n, n), fill_value=a_bar.mean()) B = b - b_bar - b_bar.T + np.full(shape=(n, n), fill_value=b_bar.mean()) - cov_ab = np.sqrt(np.nansum(A * B)) / n std_a = np.sqrt(np.sqrt(np.nansum(A**2)) / n) std_b = np.sqrt(np.sqrt(np.nansum(B**2)) / n) - return cov_ab / std_a / std_b df = pd.DataFrame(np.random.normal(size=(100, 3)))