Day 7: Spearman's Rank Correlation Coefficient

  • + 1 comment
    #python
    n=int(input())
    X=list(map(float, input().split()))
    Y=list(map(float, input().split()))
    res=[(sorted(X).index(X[i])-sorted(Y).index(Y[i]))**2 for i in range(n)]
    srcc=1-(6*sum(res)/(n*(n**2-1)))
    print(round(srcc, 3))