I am trying to parallelise the following function in Python 3.6:
def get_Q(predictors, d):
Q = 0.
for i in range(len(predictors)):
for j in range(i+1, len(predictors)):
ci = predictors[i,:]
cj = predictors[j,:]
Q += product_cols(ci, cj, d[i], d[j])
return Q
where :
predictors[,]
is an input array, with n
-rows and p
-features, andd[]
is an n
-sized array.
The function product_cols()
is defined as :
def product_cols(ci, cj, di, dj):
c = ci-cj
return np.matmul(np.transpose(np.matrix(c)), np.matrix(c))*((di-dj)**2)
where :ci[]
, cj[]
are p
-sized arrays anddi, dj
are real numbers.
Could someone help me to parallelise this simply?