We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Enter your code here. Read input from STDIN. Print output to STDOUT
import numpy as np
def covariance(x,y):
pmax=-1e9
pmax_index=-1
for i in range(5):
if (np.cov(x[i],y)[1][0]>pmax):
pmax=np.cov(x[i],y)[1][0]
pmax_index=i+1
return pmax_index
t = int(input())
for i in range(t):
n = input()
cgpa = [float(a) for a in input().split()]
coeflist = []
marks_1 = [float(x) for x in input().split()]
marks_2 = [float(x) for x in input().split()]
marks_3 = [float(x) for x in input().split()]
marks_4 = [float(x) for x in input().split()]
marks_5 = [float(x) for x in input().split()]
marks=np.array([marks_1,marks_2,marks_3,marks_4,marks_5])
print(covariance(marks,np.array(cgpa)))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Best Aptitude Test
You are viewing a single comment's thread. Return to all comments →
Enter your code here. Read input from STDIN. Print output to STDOUT
import numpy as np
def covariance(x,y): pmax=-1e9 pmax_index=-1 for i in range(5): if (np.cov(x[i],y)[1][0]>pmax): pmax=np.cov(x[i],y)[1][0] pmax_index=i+1 return pmax_index
t = int(input()) for i in range(t): n = input() cgpa = [float(a) for a in input().split()] coeflist = [] marks_1 = [float(x) for x in input().split()] marks_2 = [float(x) for x in input().split()] marks_3 = [float(x) for x in input().split()] marks_4 = [float(x) for x in input().split()] marks_5 = [float(x) for x in input().split()] marks=np.array([marks_1,marks_2,marks_3,marks_4,marks_5]) print(covariance(marks,np.array(cgpa)))