You are viewing a single comment's thread. Return to all comments →
20 p
def sumarr(ax): s=0 for i in ax: s+=i return s def dot(ax1,ax2,n): p=0 for i in range(n): p+=ax1[i]*ax2[i] return p def num(ax1,ax2,n): num = n*dot(ax1,ax2,n)-sumarr(ax1)*sumarr(ax2) return num def den(ax1,ax2,n): den1 = (n*dot(ax1,ax1,n)- sumarr(ax1)**2)**0.5 den2 = (n*dot(ax2,ax2,n)- sumarr(ax2)**2)**0.5 return den1*den2 def cor(ax1,ax2,n): corr = num(ax1,ax2,n)/den(ax1,ax2,n) return round(corr,2) ax1=[] ax2=[] ax3=[] n = int(input()) for i in range(n): l=list(map(int, input().split())) ax1.append(l[0]) ax2.append(l[1]) ax3.append(l[2]) print(cor(ax1,ax2,n)) print(cor(ax2,ax3,n)) print(cor(ax1,ax3,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 →
20 p