I have two 2D numpy arrays (simplified in this example with respect to size and content) with identical sizes.
An ID matrix:
1 1 1 2 2
1 1 2 2 5
1 1 2 5 5
1 2 2 5 5
2 2 5 5 5
and a value matrix:
14.8 17.0 74.3 40.3 90.2
25.2 75.9 5.6 40.0 33.7
78.9 39.3 11.3 63.6 56.7
11.4 75.7 78.4 88.7 58.6
79.6 32.3 35.3 52.5 13.3
My goal is to count and sum the values from the second matrix grouped by the IDs from the first matrix:
1: (8, 336.8)
2: (9, 453.4)
5: (8, 402.4)
I can do this in a for loop but when the matrices have sizes in thousands instead of just 5x5 and thousands of unique ID's, it takes a lot of time to process.
Does numpy have a clever method or a combination of methods for doing this?