pylab inline import random import matplotlib pyplot as plt 10 10 for i

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
%pylab inline
import random
import matplotlib.pyplot as plt
n = 10
k = 10
x = []
y = []
for i in range(n):
x.append(random.random())
y.append(random.random())
part = 1. / k
x.sort()
y.sort()
numInPartsX = [0 for i in range(k)]
numInPartsY = [0 for i in range(k)]
j = 0
step = part
print x
print
print y
def gist(x, numInParts, part):
j = 0
step = part
for i in x:
while 1:
if i < step:
numInParts[j] += 1.
break
else:
j += 1
step += part
return numInParts
print gist(x, numInPartsX, part)
print
print gist(y, numInPartsY, part)
x2 = 0.
for i in range(k):
if numInPartsY[i] != 0:
x2 += (numInPartsX[i] / k - numInPartsY[i] / k) ** 2 / numInPartsY[i]
print x2
print x2 * k