usr bin env python coding utf-8 10 16 06 15 23 30 05 25 30 20 14 06 Mx

 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
X = (2, 3, 6)
Y = (3, 4)
M = ((0.10, 0.16, 0.06),
(0.15, 0.23, 0.30))
#X = (0.1, 0.3, 0.6)
#Y = (2, 5)
#M = ((0.05, 0.25, 0.30),
#(0.20, 0.14, 0.06))
Mx = sum(sum([x*p for x,p in zip(X,line)]) for line in M)
My = sum(y*sum(line) for y,line in zip(Y,M))
Dx = sum(sum([((x-Mx)**2)*p for x,p in zip(X,line)]) for line in M)
Dy = sum(((y-My)**2)*sum(line) for y,line in zip(Y,M))
Muxy = 0
for j, x in enumerate(X):
for i, y in enumerate(Y):
Muxy += (x-Mx)*(y-My)*M[i][j]
print "Mx:", Mx
print "My:", My
print "Dx:", Dx
print "Dy:", Dy
print "Muxy:", Muxy