Given the numeric arrays P (N), D (N, N), I want to calculate the array A (N):
A_i = SUM(P_i - P_j) where j is such that D[i][j] is True A_i = 0 otherwise
So,
A_i = N*P_i - (P_m + P_n+...) where D[i][m], D[i][n],... are all True
I could write above using a double loop and enumerate (), but it is rather slow. Just wondering how I can write this in terms of numpy ufuncs.
source share