Increment Numpy array with repeated indices

前端 未结 4 656
渐次进展
渐次进展 2020-11-28 13:52

I have a Numpy array and a list of indices whose values I would like to increment by one. This list may contain repeated indices, and I would like the increment to scale wit

4条回答
  •  無奈伤痛
    2020-11-28 14:23

    After you do

    bbins=np.bincount(b)
    

    why not do:

    a[:len(bbins)] += bbins
    

    (Edited for further simplification.)

提交回复
热议问题