I have two arrays A
and B
:
A=array([[ 5., 5., 5.],
[ 8., 9., 9.]])
B=array([[ 1., 1., 2.],
[ 3., 2., 1.]])
Anywhere there is a "1" in B
I want to sum the same row and column locations in A
.
So for example for this one the answer would be 5+5+9=10
I would want this to continue for 2,3....n (all unique values in B
)
So for the 2's... it would be 9+5=14 and for the 3's it would be 8
I found the unique values by using:
numpy.unique(B)
I realize this make take multiple steps but I can't really wrap my head around using the index matrix to sum those locations in another matrix.