Skip to content

Instantly share code, notes, and snippets.

@hihell
Created December 7, 2020 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hihell/a578251c0497d3a8abe82db4e4088093 to your computer and use it in GitHub Desktop.
Save hihell/a578251c0497d3a8abe82db4e4088093 to your computer and use it in GitHub Desktop.
pairwise variation
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