Вы можете использовать маску для исключения / включения значений, которые будут добавлены:
import numpy as np
a = np.array([0,0,1,1,1,2,3,3,3,3])
b = np.arange(20).reshape(10, 2)
mask = a[:,None]==np.arange(4)
result = np.sum(b[:,:,None]*mask[:,None,:],axis=0)
вывод:
print(mask*1) # rows of b that will be added in each column
[[1 0 0 0]
[1 0 0 0]
[0 1 0 0]
[0 1 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]
[0 0 0 1]
[0 0 0 1]
[0 0 0 1]]
print(result) # result: 4 sums for each column of b
[[ 2 18 10 60]
[ 4 21 11 64]]
print(result.transpose()) # vertical representation:
[[ 2 4]
[18 21]
[10 11]
[60 64]]