You are viewing a single comment's thread. Return to all comments →
My solution in Python3. It was accepted, but I don't understand why putting math = phys = chem = [] instead of three lines gives a wrong answer.
#Denominator def getden(siga,siga2,n): return ((n*siga2)-(siga)**2)**0.5 #Prod Corr calculation def prod_corr(x,y,n): sigx = sum(x) sigy = sum(y) sigxy = sum(x[i]*y[i] for i in range(0,n)) sigx2 = sum([i*i for i in x]) sigy2 = sum([i*i for i in y]) return float((n*sigxy)-(sigx*sigy))/(getden(sigx,sigx2,n)*getden(sigy,sigy2,n)) #Read input n = int(input()) math = [] phys = [] chem = [] for i in range(0,n): temp = [int(j) for j in input().split("\t")] math.append(temp[0]) phys.append(temp[1]) chem.append(temp[2]) print("{:.2f}".format(prod_corr(math,phys,n))) print("{:.2f}".format(prod_corr(phys,chem,n))) print("{:.2f}".format(prod_corr(math,chem,n)))
Seems like cookies are disabled on this browser, please enable them to open this website
Day 5: Computing the Correlation
You are viewing a single comment's thread. Return to all comments →
My solution in Python3. It was accepted, but I don't understand why putting math = phys = chem = [] instead of three lines gives a wrong answer.