It is best to give an example.
Let's say vector A consists of:
A = {3 ,2 ,1 ,4 ,6 ,3 ,8 ,4}
and vector B consists of:
B = {1.5,2 ,2 ,1.5,3 ,3 ,3 ,2}
The unique values in vector B are {1.5, 2, 3}
I want the resulting vector RESULT to be:
RESULT[0] = Average(A given B=1.5) = Average(3,4)
RESULT[1] = Average(A given B=2 ) = Average(2,1,4)
RESULT[2] = Average(A given B=3 ) = Average(6,3,8)
What is the most efficient way of calculating this. My own method is to loop over unique elements of B, and for each of them, loop over each B value trying to match that unique number and keep summing up the corresponding element of vector A in each match, also counting the number of matches so I can find the average.
This is too slow. since My vector A is 8M elements, and vector B consists of 0.5M unique values.
Any help would be appreciated.