performance - numpy count sum of costs for points in same group -


i have vector each point @ index belong group vector[i]

vector=np.array([[1,1,4,1,4,3,1]]) 

i have cost every point:

cost=np.array([[10,10,40,1,4,1,2]]) 

i want compute in efficient way without loops sum of costs each group, point.

for example except output:

[[23,23,44,23,44,1,23]] 

for group 1 10+10+1+2 = 23
for group 2 40+4 = 44
for group 3 1

just:

counts = np.bincount(vector, weights=cost) output = counts[vector] 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -