Created
December 7, 2020 18:46
-
-
Save hihell/a578251c0497d3a8abe82db4e4088093 to your computer and use it in GitHub Desktop.
pairwise variation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
n = 3 | |
d = np.random.randn(n) | |
acc = 0 | |
for i in range(n): | |
for j in range(n): | |
acc += (d[i] - d[j])**2 | |
pairwise_var1 = acc / (n*(n)) / 2 | |
pairwise_var2 = acc / (2*n*(n-1)) / 2 | |
var = np.var(d) | |
print('pairwise1:', pairwise_var1, 'pairwise2:', pairwise_var2, 'var:', var) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment